Aller au contenu

  Open an example to learn how to place figures in the document Overleaf

To change the positioning of an image (and add caption and reference to it), we need to be able to treat it as an object inside the LaTeX document. This object needs to have a few desirable properties -

  1. The contents of this object, i.e., the image, cannot be broken over a page.
  2. We should be able to specify the position of this object in the document.
  3. We should be able to add a caption to this object.
  4. We should be able to add a reference to this object, so that it can be cross-referenced elsewhere in the document.

This is where floats come in handy.

Floats

In LaTeX, floats are used to contain things that must be placed inside a single page, i.e., they cannot be broken over multiple pages. floats can be used to contain tables and figures, but we can define new custom floats as well. Here is how floats address the issues mentioned above -

  1. The entity contained in a float is placed in a single page. If the entity (an image, for example) can not be contained in the space left in the current page, it is placed at the top of the next page.
  2. floats can be positioned wherever we specify - top, middle, bottom, left, right, and so on.
  3. They can have a caption describing them.
  4. They are numbered (so we can add references to them). This lets us produce a list of figures or a list of tables that we can include in our document.

To create floats to contain images, we use the figure environment.

Figures

Here is how we create a floating figure -

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

The placement specifier parameter allows us to have a greater control over where a figure is placed. But while LaTeX will do its best to follow the placement we specify, it may not always be possible for it to adhere to it. Let us take a look at different placement specifiers and what they do before we dive into examples.

Specifier Permission
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 Put 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 (\usepackage{float}). This is somewhat equivalent to h!, though some errors may arise if you have too many consecutive floats with [H].
Example
    \begin{figure}[hbt!]
    ... figure contents...
    \end{figure}


Centering a Figure

We often need to center figures, particularly in presentations. This can be achieved by using \centering -

\begin{figure}[hbt!]
 \centering
 \includegraphics{birds}
\end{figure}

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX