Place a figure exactly here in LaTeX (stop it floating)

Help centre › LaTeX › Figures · Packages: float, placeins

Give the figure the options [htbp] (or [!htbp]) so LaTeX may put it here, at the top or bottom of a page, or on a page of floats; that usually keeps it close. To force it exactly where it is written, load \usepackage{float} and use \begin{figure}[H]; to stop figures drifting past a section, load \usepackage[section]{placeins}, and to print every waiting figure now, use \clearpage.

A complete example

A whole document: paste it into an empty project and compile it.

\documentclass{article}
\usepackage{float}
\usepackage{lipsum}
\begin{document}
\section{Method}
\lipsum[1]

\begin{figure}[H]
  \centering
  \rule{0.6\textwidth}{0.3\textwidth}% \includegraphics[width=0.6\textwidth]{figures/setup}
  \caption{The setup, printed exactly here.}
  \label{fig:setup}
\end{figure}

As Figure~\ref{fig:setup} shows, \lipsum[2]
\end{document}

Why figures move, and what the options mean

figure and table are floats: LaTeX holds them back and places them where they fit, so that a page never ends with a large gap. The optional argument lists where a float may go, and LaTeX tries the places in this order:

  • h: here, at the point where it is written, if there is room.
  • t: at the top of a page (this one or a later one).
  • b: at the bottom of a page.
  • p: on a page holding only floats.
  • !: ignore the usual limits on how much of a page floats may take (see below).

Good default: [htbp]

Without an option, a figure in the standard classes may go only [tbp]. Writing [h] alone is too strict: if the figure does not fit right there it has nowhere else to go, so LaTeX changes it to [ht] with a warning, and figures that still cannot be placed hold up every later figure until the end of the chapter or document. [htbp] gives LaTeX every option; [!htbp] also lets it break the spacing limits.

Write the figure just after the paragraph that first refers to it. A figure that is larger than the space left on the page cannot be placed here whatever the option says; make it smaller, or let it go to the top of the next page.

Exactly here: [H] from the float package

\usepackage{float} adds the option [H]: the figure is no longer a float and is printed exactly where it is written, like a picture in the text. If it does not fit on the current page, it moves to the next page and leaves a gap at the bottom of this one. Use it for figures that must stay with a step of the text, not as a habit for every figure.

Keep figures in their section: \FloatBarrier

\usepackage{placeins} provides \FloatBarrier: no float written before it may be printed after it. With the option [section], every \section has an invisible barrier, so figures never drift into the next section. Unlike \clearpage, it starts no new page.

\documentclass{article}
\usepackage[section]{placeins}
\usepackage{lipsum}
\begin{document}
\section{Results}
\lipsum[1]
\begin{figure}[htbp]
  \centering
  \rule{0.7\textwidth}{0.4\textwidth}
  \caption{Main result.}\label{fig:main}
\end{figure}
\lipsum[2]
\FloatBarrier % also possible by hand, anywhere
\section{Discussion}
Figure~\ref{fig:main} stays in the Results section.
\end{document}

All figures pile up at the end: \clearpage and the float limits

When many figures come close together, the ones that do not fit wait in a queue and later ones may not overtake them. \clearpage ends the page and prints every waiting float, on float pages if needed; put it at the end of a chapter or section full of figures.

The standard limits allow floats to take at most part of a text page. If figures keep going to float pages of their own, relax the limits in the preamble:

\renewcommand{\topfraction}{0.85}     % up to 85% of a page may be floats at the top
\renewcommand{\bottomfraction}{0.7}
\renewcommand{\textfraction}{0.15}    % at least 15% of a text page is text
\renewcommand{\floatpagefraction}{0.7} % a float page must be at least 70% full
\setcounter{topnumber}{3}
\setcounter{totalnumber}{4}

Common mistakes

In journal templates

Errors you may meet

In Manulyx

Insert → Figure → Upload from computer… uploads an image into figures/ and inserts a figure for it; From project files uses an image already in the project. PDF, PNG and JPG work with pdfLaTeX.

Write in Manulyx for free · Journal templates

Related

The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained