Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 38 ยท Tables, Figures and Lists

Floats, Captions and Placement

Understand LaTeX floats: the figure and table environments, captions and labels, placement specifiers h t b p and !, the float package H, lists of figures and tables, and how to stop figures from drifting.

Beginners are often surprised that a figure does not appear exactly where they typed it. That is by design. A picture or a table is a large block that cannot be split across pages, so putting it at the exact spot could leave a huge gap at the bottom of the page. LaTeX treats these blocks as floats: it is allowed to move them to a nearby place where they fit. This lesson explains how floats work, how to caption and number them, and how to influence where they land.

What is a float?

A float is content wrapped in an environment that LaTeX may place away from where it appears in the source. There are two standard floats:

Environment For Caption label List command
figure images, diagrams, plots Figure \listoffigures
table tables Table \listoftables

The tabular environment and \includegraphics are not floats by themselves; they are the content that you place inside one.

LATEX
\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.6\textwidth]{results}
  \caption{Accuracy of the three models on the test set.}
  \label{fig:results}
\end{figure}

Every part has a role:

  • [htbp] is the placement hint (below).
  • \centering centers the content (use it instead of the center environment inside a float, which adds extra space).
  • \caption{...} creates the numbered caption: "Figure 1: Accuracy of ...".
  • \label{...} names it so you can write Figure~\ref{fig:results} in the text. The label must come after the caption, because it takes the number of the most recent counter that was increased.

For a table:

LATEX
\begin{table}[htbp]
  \centering
  \caption{Scores by group.}
  \label{tab:scores}
  \begin{tabular}{lc}
    \toprule
    Group & Mean \\
    \midrule
    A & 4.2 \\
    B & 3.9 \\
    \bottomrule
  \end{tabular}
\end{table}

By convention the caption of a table goes above it and the caption of a figure goes below it. Just change the order of \caption and the content.

Placement specifiers

The letters in the square brackets tell LaTeX where the float is allowed to go. LaTeX tries them in a fixed sequence, not in the order you wrote them.

Letter Meaning
h here, at this position in the text, if there is room
t at the top of a page
b at the bottom of a page
p on a separate page of floats
! override the internal limits (such as the maximum fraction of a page that floats may use)
H exactly here (needs the float package; not a real float any more)

[htbp] is a safe, generous default and lets LaTeX choose the best option. [h] alone is often too strict: it behaves like [ht] and the float may still drift. [!htbp] removes limits. [H] forces the position:

LATEX
\usepackage{float}
...
\begin{figure}[H]
  ...
\end{figure}

Use H sparingly. A forced figure can leave a large blank space at the end of the previous page. A better habit: refer to the float by number in the text (as Figure~\ref{fig:results} shows), so the reader does not need it exactly here.

flowchart LR
  A["figure in the source"] --> B{"fits here and h allowed?"}
  B -->|yes| C["placed here"]
  B -->|no| D{"top of a page and t allowed?"}
  D -->|yes| E["placed at top"]
  D -->|no| F{"bottom and b allowed?"}
  F -->|yes| G["placed at bottom"]
  F -->|no| H["held back for a float page (p)<br/>or the next page"]

Floats never move to an earlier page than their source position. They queue in order, so one stuck float can hold back all that follow.

Why does my figure float away?

Typical reasons:

  • The figure is too tall for the rest of the page and LaTeX waits for the next page.
  • The placement list is too restrictive, for example [b] on a figure placed mid-page.
  • A float queue has built up: too many figures in a row, so some are delayed to the end of the chapter. The message is "Too many unprocessed floats".
  • A figure larger than the allowed fraction of a page (80% by default for floats at the top) is only placed on its own page.

Remedies, in order of preference: make the figures smaller, move the figure environment earlier in the source (it can never move earlier than where it is written), use [!htbp], add \clearpage to flush all pending floats at a chapter end, and only as a last resort use H. The placeins package gives \FloatBarrier, which stops floats from crossing a section boundary: load it with \usepackage[section]{placeins}.

Try the caption numbering behaviour below. The stand-in reads figure and table environments from the source and produces the numbered captions and the "List of Figures" and "List of Tables" that \listoffigures and \listoftables would print, with separate counters for figures and tables. It is a model of the counters, not of the page layout.

Caption counters and lists (stand-in, not a real compiler)

Notice that figures and tables have independent counters: the first table is Table 1 even though it comes after Figure 1.

Captions in detail

LATEX
\caption[Short title for the list]{A long, full caption that explains the figure.}

The optional argument in brackets is the entry for \listoffigures; use it when the caption is long. A good caption stands on its own: it says what is shown, units, and what to notice. For formatting (smaller font, bold label, left alignment), use the caption package:

LATEX
\usepackage{caption}
\captionsetup{font=small, labelfont=bf, format=hang}

If you need a caption outside a float (for example inside a longtable or a non-floating figure), \captionof{figure}{...} from caption does it.

Float placement in two-column documents

In twocolumn mode figure is one column wide. For a figure across both columns, use the starred forms figure* and table*; these can only be placed at the top of a page (t) or on a float page.

Wrapping text around a figure

The wrapfig package makes text flow around a small image:

LATEX
\usepackage{wrapfig}
\begin{wrapfigure}{r}{0.35\textwidth}
  \centering
  \includegraphics[width=0.33\textwidth]{photo}
  \caption{A small photo.}
\end{wrapfigure}

It works best for narrow figures in the middle of long paragraphs, and it is fragile near page breaks. Use it with care.

Lists of figures and tables

After placing \listoffigures and \listoftables (usually right after \tableofcontents), each list collects all captions with page numbers. As with contents, you need a second compile for new entries to show up. Pass a short caption in brackets to keep the lists tidy.

Referencing floats

Always refer to a float by number, not by position:

LATEX
Figure~\ref{fig:results} shows the accuracy; see Table~\ref{tab:scores}.

Avoid words such as "the figure above" or "below": since floats move, those words may be wrong. The cleveref package goes further with \cref{fig:results}, which writes "fig. 1" or "Figure 1" for you.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is a figure allowed to move away from where you typed it?

    Floats are placed where there is room, which avoids large empty gaps.
  2. 2. Where does the \label go for a correct figure number reference?

    \label records the current counter value, which \caption has just increased.
  3. 3. What does [H] (with the float package) do?

    H forces the exact position and can leave blank space.
  4. 4. By convention, where is the caption of a table placed?

    Table captions go above, figure captions below.

Summary

  • figure and table are floats: LaTeX may move them to a good place.
  • Put content, \caption and then \label inside; table captions go above, figure captions below.
  • [htbp] is a good default; ! relaxes limits; H forces position.
  • Refer to floats by number with \ref, and use \clearpage or \FloatBarrier to control drift.
  • \listoffigures and \listoftables build lists from captions.

Next: Labels and Cross-references