# 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*.

```latex
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](/files/H6PWTuqKWcqTR9hseX2J)

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 `t`op of the document, despite being declared below the text.

```latex
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}
```

<figure><img src="/files/Gxeax1S3bDXqycH9gPsN" alt="Example of bar graph" width="375"><figcaption></figcaption></figure>

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.

```latex
\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.
```

<figure><img src="/files/FELZA4RRipZjfxildbXy" alt="Example of text wrapping a figure" width="563"><figcaption></figcaption></figure>

For the commands in the example to work, you have to import the [`wrapfig` package](https://ctan.org/pkg/wrapfig?lang=en). To use `wrapfig`, include the following line in the document preamble:

```latex
\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:

```latex
\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](#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.

## Learn More

* For a more complete article about image positioning, see [Positioning images and tables](https://learn.overleaf.com/learn/Positioning_images_and_tables) on Overleaf's [Learn LaTeX](https://www.overleaf.com/learn)
* [Open an images example in Overleaf](https://www.overleaf.com/project/new/template/19397?id=65443742\&templateName=Inserting+Images\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)
* [How do I insert an image at a specific point in the document?](https://www.overleaf.com/learn/latex/Questions/How_do_I_insert_an_image_at_a_specific_point_in_the_document%3F) on Overleaf's [Learn LaTeX](https://www.overleaf.com/learn)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overleaf.com/writing-and-editing/inserting-images/positioning-figures.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
