Figures are a normal part of most projects, and they may be included in your LaTeX document using a number of different methods. We will now look at some of the methods including their faults.

We say if often, but that's because it's very imporant. The methods we explain here are not necessarily always the best option or approach for your problem. Use the internet to find other tutorials on the same or different methods. This will improve your LaTeX knowledge by a lot, we assure you!

Some relevant documentation:

To enable figures in your document, include the package graphicx. ( \usepackage{graphicx} ) Additional packages will be discussed when needed.

Page content

Caption

It is usually beneficial to include caption to your images. To do so, simply use the command \caption{'text'} either below or above your figure (usually below for images and above for tables).

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Caption written below figure.}
\end{figure}


\begin{figure}
    \centering
    \caption{Caption written above figure.}
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
\end{figure}


Customized captions

Defining your own caption

If you e.g. want to attach a source to your figures in a specific and consistent manner, a self-defined caption may be an option.

% In setup
\newcommand{\source}[1]{\vspace{-4pt}{\hfill \footnotesize{Source: {#1}} } }


% In document
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg} 
    \caption{Flow around cylinder}
    \source{Your source}
\end{figure}

Caption package

The plain captions has a typeset as an ordinary paragraph, with no remarkable visual difference from the rest of the text. If you'd like to change this in any way possible, check out the documentation on the caption package.

Please note that the caption package is only controlling the look & feel of the captions. It does not control the placement of the captions. (But you could do so by using other packages like the floatrow package.

Following is a short example displaying the caption package.

% In setup
\usepackage[font=it,labelfont=bf]{caption}


% In document
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{figure}

List of figures

A list of figures is included in your document by use of the command \listoffigures. As descriptions in the list of figures, the caption defined for each figure is used.


Supress caption in list of figures

To supress the Figure #: (or Table #: ), simply write your desired text without using the caption command. However, note that this will remove the figure from your list of figures as well.

\subsection{Caption Supress figure:}
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Caption written using command}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg} 
    
    Caption written without using command
\end{figure}


Specified caption in list of figures

If the figure caption is long, it is often desired to define another caption to be used in the list of figures. To do so, use the caption options \caption['short caption']{'long caption'}

\listoffigures
\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}    
	\caption[Short caption]{Long caption}
\end{figure}

Figure environment

The most common method of including images is using the Figure environment. 

\begin{figure}[placement specifier]
... figure contents ...
\end{figure}

Positioning

The placement specifiers available when inserting figures are as shown in the table below. This table is taken from LaTeX Floats, Figures and Captions, so check it out for more detailed information.

SpecifierPermission
hPlace the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
tPosition at the top of the page.
bPosition at the bottom of the page.
pPut on a special page for floats only.
!Override internal parameters LaTeX uses for determining "good" float positions.
HPlaces the float at precisely the location in the LaTeX code. Requires the float package, i.e., \usepackage{float}

It is also common to use the command \centering to center the image on the page. For example:

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
\end{figure}


Label

To later reference your figure, include a label inside the environment. Note that the label has to be defined after the caption.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
    \label{fig:Flow around cyl}
\end{figure}


As seen in Figure \ref{fig:Flow around cyl} ...

Although we will not cover them here, there are many other options available when referencing. More information may be found at e.g. LaTeX Lables and Cross-referencing. One of these options are the command \autoref{'label'} in the package hyperref.

As seen in \autoref{fig:Flow around cyl} ...

Path in Overleaf

It is often desired to organize your project in different folders such as SectionsImagesCode etc. If so, it is recommened to provide the absolute path when including images. Commonly, the main .tex file directory is denoted as ./, also seen in the example below. If you are unfamiliar to relative and absolute path, an in-depth explanation can be found at Overleaf on Image path.

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{./Images/CylinderImage.jpg}
\end{figure}

Size

The size of the image may be specified using a variety of commands. Some of the most used are: \width, \height, \scale and \angle.

\begin{figure}	% First image displayed below
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
\end{figure}

\begin{figure}	% Not displayed, but similar to the first image
    \centering
    \includegraphics[width=6cm, height=4cm]{CylinderImage.jpg} 
\end{figure}

\begin{figure}	% Not displayed, but similar to the first image
    \centering
    \includegraphics[scale=0.65]{CylinderImage.jpg} 
\end{figure}

\begin{figure}	% Second image displayed below
    \centering
    \includegraphics[width=0.25\textwidth, angle=45]{CylinderImage.jpg} 
\end{figure}

Subfigures

Subfigures are incorporated in the standard graphicx package. However, it is recommended to also include the package subcaption which uses subfloats within a single float.  

% From experience, it is usually not enough space to put two subfigures with width=0.5\textwidth next to each other
% We have therefore chosen width=0.495\textwidth

% First image below
\begin{figure}
    \centering
    \begin{subfigure}{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/CylinderImage.jpg}
        \caption{Flow around circular cylinder}
    \end{subfigure}
    \begin{subfigure}{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/Streamlines_Re100.png}
        \caption{Flow around square cylinder}
    \end{subfigure}
    \\  % Makes new line. This may also be used when inserting wrapfigures
    \begin{subfigure}{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/Cavity_1000_streamlines.png}
        \caption{Flow in lid-driven cavity}
    \end{subfigure}
    \begin{subfigure}{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/Streamlines_Re40.png}
        \caption{Flow around square cylinder}
    \end{subfigure}
    \caption{Various flows. Notice how the dimensions of the individual images affects their size in the subplots.}
\end{figure}

% To align the figures by caption, we may use the placement specifier 't'
% Second image below
\begin{figure}
    \centering
    \begin{subfigure}[t]{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/CylinderImage.jpg}
        \caption{Flow around circular cylinder}
    \end{subfigure}
    \begin{subfigure}[t]{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/Streamlines_Re100.png}
        \caption{Flow around square cylinder}
    \end{subfigure}
    \\
    \begin{subfigure}[t]{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/Cavity_1000_streamlines.png}
        \caption{Flow in lid-driven cavity}
    \end{subfigure}
    \begin{subfigure}[t]{0.495\textwidth}
        \includegraphics[width=\textwidth]{./Images/Streamlines_Re40.png}
        \caption{Flow around square cylinder}
    \end{subfigure}
    \caption{Various flows. Notice how the dimensions of the individual images affects their size in the subplots.}
\end{figure}

Wrapfigure environment

The package wrapfig allowes figures or tables to have text wrapped around them. Information regarding the wrapfig package may be found at Overleaf on Wrapping text around figures or in the wrapfig package documentation.

The following image is taken from the package documentation, and sums up the most essential parameters.

  • The width may be defined as in the size section, and does not necessarily have to be in cm. 
  • The available placement specifiers are listed in the table below.
  • Number of narrow lines specifies how many lines should be 'cut' in the height. Based on personal experience, this option is handy when the image does not wrap itself the way I want it to.
  • The overhang is the offset of the figure.
Placement specifiers
rRRight side of the text
lLLeft side of the text
iIInside edge–near the binding (in a twoside document)
oOOutside edge–far from the binding

Examples

Lets look at some examples to better understand what's happening.

Placement

% First image below
... fill text
\begin{wrapfigure}{r}{0.5\textwidth}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{wrapfigure}
... fill text

% Second image below
... fill text
\begin{wrapfigure}{l}{0.5\textwidth}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{wrapfigure}
... fill text


Number of narrow lines

% First image below
... fill text
\begin{wrapfigure}[13]{r}{0.5\textwidth}	% If you count, you will see that 13 lines are cut to make place for this figure
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{wrapfigure}
... fill text


% Second image below
... fill text
\begin{wrapfigure}[16]{r}{0.5\textwidth}	% If you count, you will see that 16 lines are cut to make place for this figure
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{wrapfigure}
... fill text

Overhang

The default value for overhang is 0pt.

% First image below
... fill text
\begin{wrapfigure}{r}[0pt]{0.5\textwidth}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{wrapfigure}
... fill text


% Second image below
... fill text
\begin{wrapfigure}{r}[30pt]{0.5\textwidth}
    \centering
    \includegraphics[width=0.5\textwidth]{CylinderImage.jpg}
    \caption{Flow around cylinder}
\end{wrapfigure}
... fill text

Issues

Be careful using the wrapfigure environment near

  • lists
  • end of pages

as this may cause problems.



  • No labels