Figure placement in LaTeX (h, t, b, p, H)
The optional argument of figure lists the places LaTeX may use: h (here), t (top of a page), b (bottom) and p (a page with floats only). \begin{figure}[H] from the float package puts the figure exactly where it stands in the source.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{graphicx}
\usepackage{float}
\usepackage{placeins}Allow several places
[htbp] allows all four places. The order of the letters has no effect; LaTeX tries h first in any case. Without an argument, the article class uses tbp. An added !, as in [!htbp], tells LaTeX to ignore its limits for the number of floats and the share of a page they may cover.
Text before the figure.
\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\end{figure}
Text after the figure.Put the figure exactly here
With the float package, [H] turns the float off for this figure: it appears between the two paragraphs around it. If the rest of the page is too short, the figure moves to the next page and leaves the rest of this page empty.
Text before the figure.
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\end{figure}
Text after the figure.Keep figures inside their section
\FloatBarrier from the placeins package is a line that no float may cross: figures and tables from the source before it appear before it. Unlike \clearpage, it starts a new page only when floats are still waiting. \usepackage[section]{placeins} sets this barrier before every \section.
\section{Results}
Text of the section.
\begin{figure}[tbp]
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\end{figure}
\FloatBarrier
\section{Discussion}
Text of the next section.Print all waiting figures
\clearpage ends the page and prints every float that has not been placed yet, on pages of their own if needed. Use it before a new chapter or before the bibliography.
\begin{figure}[tbp]
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\end{figure}
\clearpage
\section{References}Pitfalls
[h]alone is a weak request. When the figure does not fit at that place, LaTeX changeshtoht, reports `h' float specifier changed to `ht' and moves the figure to the top of a later page.- A figure that fits none of its allowed places waits, and every later figure waits behind it, because LaTeX keeps figures in order. They all appear at the end of the document or at the next
\clearpage. The usual cause is an image that is too high fortandbwhilepis not allowed. - When too many floats wait, LaTeX stops with Too many unprocessed floats.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
float - Package
placeins - How-to Figure caption and label in LaTeX
- Error `h' float specifier changed to `ht'
- Error Too many unprocessed floats
- Package
graphicx