Tx · LaTeX & TikZ

How to Fix a Misplaced Figure in LaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Allow sensible positions

    Use a placement option such as [htbp] to let LaTeX choose a suitable location near the figure.

  2. 2. Check the float queue

    Figures can move when there is not enough room or earlier figures are still waiting to be placed.

  3. 3. Set a boundary if needed

    Use FloatBarrier to keep earlier figures from moving past a chosen point.

  4. 4. Force placement sparingly

    Use [H] from the float package only when the figure must stay exactly at its source location.

A figure appearing later than its source code is usually normal LaTeX behavior, not a broken reference or a misplaced command. The figure environment is a float: LaTeX is allowed to move it to make the page layout work.

The best fix depends on what you mean by “misplaced.” If you want the figure near its mention, give LaTeX several acceptable positions. If you need it to stay within a section, set a boundary. If it must appear exactly at that point, use a force-placement option carefully.

Why LaTeX moves figures

A figure may not fit in the space left on the page, or LaTeX’s layout rules may not permit it there. The figure is then queued for a later page. Subsequent figures can also wait behind an earlier float, so one figure that cannot be placed may cause several to move.

The placement option in square brackets tells LaTeX where it is allowed to try placing a float:

  • h means here, approximately at the point in the source.
  • t means at the top of a page.
  • b means at the bottom of a page.
  • p means on a page devoted to floats.

These letters are permissions, not guarantees. For example, [htbp] gives LaTeX several choices; it does not demand that the figure appear precisely “here.”

Start with flexible placement

For most figures, use [htbp] or simply omit the option and let LaTeX use its defaults. Here is a complete example that compiles without an external image file:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

The diagram illustrates the layout used in this example.

\begin{figure}[htbp]
  \centering
  \fbox{\rule{0pt}{3cm}\rule{5cm}{0pt}}
  \caption{A placeholder diagram.}
  \label{fig:placeholder}
\end{figure}

As Figure~\ref{fig:placeholder} shows, the figure can float to a
nearby suitable location.

\end{document}

The framed rule stands in for an image, so you can test the float behavior as written. In a real document, replace it with a command such as \includegraphics[width=0.7\linewidth]{diagram}. Put \label after \caption so the reference picks up the figure number.

If LaTeX keeps moving the figure too far away, check that it is not unusually large. A figure that cannot fit in the remaining page space may have to move. Reducing its width or height can make a nearby placement possible.

Keep floats from crossing a boundary

If figures should not drift beyond a section or subsection, the placeins package provides \FloatBarrier. It requires LaTeX to place pending floats before proceeding past the barrier. For example:

\usepackage{placeins}

% ... figure environments for this section ...
\FloatBarrier
\section{Next section}

Some document classes or package settings insert barriers at section boundaries automatically, but do not assume that behavior: add a barrier explicitly when you need one. A barrier controls how far floats may travel; it does not promise that a figure will land at one exact point.

Another option is \clearpage, which outputs pending floats and then starts a new page. It is stronger than a barrier and can create an unwanted page break, so use it only when that page break makes sense—for example, before a major document division.

Force exact placement only when necessary

The float package defines the uppercase placement option [H], which tells LaTeX to put the figure at that point rather than treat it as a normal floating figure. Add \usepackage{float} to the preamble, then write:

\begin{figure}[H]
  \centering
  \includegraphics[width=0.7\linewidth]{diagram}
  \caption{A diagram placed at this point.}
\end{figure}

Unlike lowercase h, uppercase H is an instruction for fixed placement. If there is not enough room for the figure, it may leave a large blank area or push the figure to the next page. It can also make page breaks less attractive. Use it when exact placement is more important than flexible page layout, not as the default for every figure.

Common mistakes

  • Using [h] as if it meant “exactly here.” It only permits placement near the source; LaTeX can still move the float.
  • Adding every letter without checking size. [htbp] offers options, but an oversized figure may still move. Resize it if necessary.
  • Using [H] everywhere. Fixed placement can produce awkward spacing and page breaks. Prefer flexible placement unless there is a specific reason to pin a figure down.
  • Confusing source order with page position. Floats are usually placed in their source order relative to other floats of the same type, but their final page position need not match the surrounding paragraphs exactly.
  • Expecting a barrier to force a location. \FloatBarrier stops floats from crossing a boundary; it does not place each one at a chosen line.

When a figure is displaced, first try [htbp] and confirm it is small enough to fit. Add \FloatBarrier if it must remain within a section, or use [H] only if it truly must appear exactly where written.

References

  1. The LaTeX Companion, 3rd edition — Frank Mittelbach and Ulrike Fischer
  2. The float package — CTAN
  3. The placeins package — CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.