Hello friends.
Thanks for all your support to the channel.
If you are new to the channel, hit the subscribe button and press the bell icon to be a part
of our notification squad.
This video is the continuation of the previous videos in the learn latex series.
If you haven’t seen those videos, check the description box for the links.
In this video, we will learn to insert images in our documents.
What is the fun in a document if doesn’t contain images.
One might also be required to add certain graphs or charts to convey certain information.
This can be done by inserting figures in the documents.
Log in to your sharelatex account and follow the code in the video to learn about addition
of figures and images in your document.
The first thing before inserting images in the file is to import the images.
Click on the upload button, then browse to the folder containing the images.
Select the image or images required for the project and click open.
Once the image gets uploaded, we can see them in the sidebar on the left.
The next step is to include the package ‘graphicx’.
We only need to include it once for the entire project.
Include this package before \begin{document} environment, then head to the line where one
needs to insert the figure.
In our case we will include it after the title of first chapter ‘Advantages of LateX’.
Write the following lines of code.
\begin{figure}, \centering, \includegraphics, \caption, \label, \end{figure}.
The lines of code from \begin{figure} to \end{figure} is the figure environment.
Any lines of code added in this environment will affect the corresponding figure.
One can observe that once you start typing \begin{figure}, sharelatex provides autocompletion
of the figure environment.
Use tab or press enter to save the pain of writing the whole code.
Next add the width parameter to the \includegraphics line to set the width of the image followed
by the image name in the parenthesis.
The image automatically resizes to the specified width.
In our case, we will type the name of image ‘ninjas.png’ in the parenthesis of \includegraphics
line.
Next update the \caption to include the caption of the figure in the document.
\label line helps to add a reference of the figure in any text we write in the document.
Lets compile the code and check the output.
We can observe that the figure is included in the document with the caption ‘Practical
Ninjas Logo’ beneath the figure.
However the image is added at the end of the page and not below the chapter title where
we wanted it to be.
To resolve this and place the figure exactly where we want it, add the parameters [ht]
to the \begin{figure} line and compile the code once more.
We now observe that the figure is shifted to the location of the code i.e) just below
the title of chapter 1.
We will insert a line of text below the chapter title and reference the newly inserted image.
Type the line ‘ The Fig. \ref{fig:logo} is the logo for Practical Ninjas’ We have
used the label name from the figure environment to reference the figure using \refer syntax.
On compiling, the line of text is added below the title of the chapter with reference to
the figure number.