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
[h]alone: it becomes[ht], and a figure that cannot be placed blocks all later figures.[H]on every figure: pages end with large gaps, and the text no longer flows around figures.- A figure larger than the text area can never be placed and keeps the queue waiting; scale it to
\textwidthand below0.8\textheight. - Putting the figure inside a
centerenvironment instead of using\centering: it adds vertical space but does not change where the figure goes. \clearpagein the middle of a paragraph to fix one figure: it leaves half-empty pages when the text changes later. Fix placement last, when the text is final.
In journal templates
- In a two-column class, a full-width
figure*ortable*can only go at the top of a page or on a float page, and at the earliest on the next page.[h],[b]and[H]do not apply to starred floats. - Many journals place figures themselves at production, and some ask for figures at the end of the manuscript or as separate files.
[H]in a journal template is often pointless and sometimes not allowed; use[htbp]or[t]there.
Errors you may meet
- LaTeX Error: Too many unprocessed floatsFigures and tables are queued faster than LaTeX can place them, often behind one that cannot be placed. Relax placements, shrink it, or add \clearpage.
- LaTeX Error: Float(s) lostA figure or table sits inside a footnote, a framed box or a similar construct LaTeX cannot place floats from, and it disappears. Move it into the text.
- LaTeX Warning: Float too large for page by <n>pt on input line <n>.A figure or table is taller than the text area, so it overprints the footer or runs off the page. Scale it to fit, or split a long table.
- LaTeX Error: Not in outer par modeA figure, table or \marginpar is inside a box, minipage, table cell or another float. Floats must be in the main text; put the box inside the float.
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
- Two figures side by side in LaTeXPut two or three images side by side in LaTeX with subcaption (each with its own (a), (b) subcaption) or with minipage (each its own Figure number).
- Wrap text around a figure in LaTeX (wrapfig)Put a figure beside the text with the text flowing around it, using the wrapfig package's wrapfigure environment, and avoid its usual problems.
- A landscape table or page in LaTeXTurn a wide table sideways: pdflscape's landscape environment rotates whole pages (upright on screen); rotating's sidewaystable rotates a float.
- Subfigures (a), (b), (c) in LaTeX and how to reference themNumber panels (a), (b), (c) inside one figure with subcaption, refer to them as Figure 1a or just (a), and change the label style.
The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained