Positioning figures

The previous section explained how to include images in your document, but the combination of text and images may not look as expected. To change this, you need to introduce a new environment.

In the next example the figure will be positioned 
right below this sentence.

\begin{figure}[h]
\includegraphics[width=8cm]{Plot}
\end{figure}
Example of positioning figures

The figure environment is used to display pictures as floating elements within the document. This means you include the picture inside the figure environment and you don't have to worry about its placement. LaTeX will position it in a such way that it fits within the flow of the document.

Sometimes we need to have more control over the way figures are displayed. An additional parameter can be passed to determine the figure positioning. In the example, begin{figure}[h], the parameter inside the brackets set the position of the figure to here. The following table lists the possible positioning values.

Parameter
Position

h

Place the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot).

t

Position at the top of the page.

b

Position at the bottom of the page.

p

Place on a special page for floats only.

!

Override internal parameters LaTeX uses for determining "good" float positions.

H

Places the float at precisely the location in the LaTeX code. Requires the float package, though may cause problems occasionally. This is somewhat equivalent to h!.

In the next example you can see a picture at the top of the document, despite being declared below the text.

In this picture you can see a bar graph that shows
the results of a survey which involved some important
data studied as time passed.

\begin{figure}[t]
\includegraphics[width=8cm]{Plot}
\centering
\end{figure}
Example of bar graph

The additional command \centering will center the picture. The default alignment is left.

Wrapping text around figures

It's also possible to wrap the text around a figure. This will make it look better when the document contains small pictures.

\begin{wrapfigure}{r}{0.25\textwidth} %this figure will be at the right
    \centering
    \includegraphics[width=0.25\textwidth]{mesh}
\end{wrapfigure}

There are several ways to plot a function of two variables, 
depending on the information you are interested in. For 
instance, if you want to see the mesh of a function so it 
easier to see the derivative you can use a plot like the 
one on the left.


\begin{wrapfigure}{l}{0.25\textwidth}
    \centering
    \includegraphics[width=0.25\textwidth]{contour}
\end{wrapfigure}

On the other side, if you are only interested on
certain values you can use the contour plot, you 
can use the contour plot, you can use the contour 
plot, you can use the contour plot, you can use 
the contour plot, you can use the contour plot, 
you can use the contour plot, like the one on the left.

On the other side, if you are only interested on 
certain values you can use the contour plot, you 
can use the contour plot, you can use the contour 
plot, you can use the contour plot, you can use the 
contour plot, you can use the contour plot, 
you can use the contour plot, 
like the one on the left.
Example of text wrapping a figure

For the commands in the example to work, you have to import the wrapfig package. To use wrapfig, include the following line in the document preamble:

\usepackage{wrapfig}

This makes the wrapfigure environment available and we can place an \includegraphics command inside it to create a figure around which text will be wrapped. Here is how we can specify a wrapfigure environment:

\begin{wrapfigure}[lineheight]{position}{width}
  ...
\end{wrapfigure}

The position parameter has eight possible values:

The uppercase version allows the figure to float. The lowercase version means exactly here.

Lower case
Upper Case
Values

r

R

right side of the text

l

L

left side of the text

i

I

inside edge–near the binding (in a twoside document)

o

O

outside edge–far from the binding

Now you can define the wrapfigure environment by means of the commands \begin{wrapfigure}{l}{0.25\textwidth} \end{wrapfigure}. Notice that the environment has two additional parameters enclosed in braces. Below, the code is explained in more detail:

{l}

This defines the alignment of the figure. Set l for left and r for right. Furthermore, if you are using a book or any similar format, use o instead for the outer edge and i for the inner edge of the page.

{0.25\textwidth}

This is the width of the figure box. It's not the width of the image itself. That must be set in the \includegraphics command. Notice that the length is relative to the text width, but normal units can also be used (cm, in, mm, etc.). See the reference guide for a list of units.

\centering

In this example the image will be centered by using its container as a reference, instead of the whole text.

For a more complete article about image positioning, see Positioning images and tables.

Open an images example in Overleaf

Last updated

Was this helpful?