Floats & placement

Your figure does not print where you wrote \begin{figure}. LaTeX detaches it from the run of text, holds it in a queue of boxes, and only sets it down when the page layout allows. That is a float, and the four letters of [htbp] are nothing more than a permit saying where LaTeX may put it down. Write [h] without knowing this and the figure tends to travel further, not less. This page covers why floats move, what each letter of [htbp] really means, the decisive difference between [H] and [h!], how \FloatBarrier and \clearpage dam the flow, the placement parameters, and the real conditions that produce ! LaTeX Error: Too many unprocessed floats.

Why your figure is not where you put it

A figure cut in half by a page break is unreadable: you cannot show the top here and the bottom overleaf. So LaTeX treats each figure or table as a single box that must not be divided, and once some text has been set it chooses where to drop that box — the top of a page, the bottom, or a page given over entirely to floats. That is a float, and the two standard environments are figure and table. Rather than have you place things by hand, LaTeX solves placement as an optimisation problem, exactly as it does line breaking. That consistency is TeX's design in miniature.

The design has two faces. On one side: a figure never splits, and its number (“Figure 1”, “Table 2”) and every cross-reference through \caption, \label and \ref line up without any effort from you. On the other: where you wrote it and where it prints diverge. That second face is not a defect but a premise. Since the prose can say “see Figure 1” by number, the figure need not sit beside the sentence — so the rule is refer by number, never by position. LaTeX also processes floats in source order, which means a later figure can overtake an earlier one. That is exactly why writing “the figure above” in running text is risky.

What h, t, b and p in [htbp] really mean

The figure and table environments accept a placement specifier as an optional argument — the square brackets in \begin{figure}[htbp] — which hands LaTeX a set of permissions: these positions are allowed. Write nothing and classes like article and book apply their default of tbp, in which h does not appear. A figure with no specifier, in other words, never had “here” among its candidates in the first place.

SpecifierMeansWhat actually happens
hhereNever allowed alone; LaTeX adds t and reports LaTeX Warning: 'h' float specifier changed to 'ht'.
ttopThe top of a text page; by default at most two floats and 70% of the text height
bbottomThe bottom of a text page; by default one float and 30% of the text height
ppageA float-only page with no text; built only when floats fill at least 50% of it
!overrideFor this float only, ignore the limits on count and height; it adds no new positions
Hfloat package onlyStops it being a float at all; without the package you get ! LaTeX Error: Unknown float option 'H'.

Most write-ups say [h] is “ignored”, but what actually happens is that LaTeX warns you and rewrites it. Set \begin{figure}[h] and the log records LaTeX Warning: 'h' float specifier changed to 'ht'., and the specifier is treated as ht. [h!] behaves the same way and yields LaTeX Warning: '!h' float specifier changed to '!ht'. Read that warning and you know on the spot why the figure jumped to the top of a page. The other misconception is the order of the letters: writing [bt] and writing [tb] change nothing. The specifier is a set of permitted positions, not a sequence; LaTeX's internal order of attempts is fixed. The practical conclusion is not to over-constrain — the wider you allow, [tbp] or [htbp], the closer the figure lands; the narrower, especially a lone [h], the further it travels.

latex
\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.6\textwidth]{plot}
  \caption{Measured values against the model}
  \label{fig:result}
\end{figure}

% refer by number, not by position; ~ keeps word and number on one line
See Figure~\ref{fig:result} for the result.

[H] versus [h!]: one of them is not a float at all

[H] is not “an even stronger here than [h!]”. It does not go through the float machinery at all. The float package replaces LaTeX's internal \@xfloat and branches to different code the instant it sees H at the head of a specifier. H is therefore never evaluated as a placement letter; the figure or table is simply set in place as a large box. That is why writing [H] without loading float stops with ! LaTeX Error: Unknown float option 'H'. [h!], by contrast, stays a float from beginning to end; it merely ignores the internal limits, and if it cannot be placed it drifts onward as usual.

Compile the two and the difference is immediate. Put a figure half the height of the text block at the same point, once with [H] and once with [!h]: the [H] figure does not budge, and if it will not fit, the surrounding text is carried to the next page with it. The [!h] figure issues its warning and then sails past the following text to the top of the next page. So [H] says “here, absolutely, and I will break the page for it”, while [!h] says “here if possible, otherwise I move”. [H] suits small figures tied to the order of the sentences — a step diagram, an algorithm sketch — but on a large figure it can empty the entire bottom half of the preceding page. You can make it the document default with \floatplacement{figure}{H}; the price is almost always a lot of white space.

latex
\usepackage{float}
% ...
\begin{figure}[H]   % not a float any more: pinned, page breaks around it
  \centering
  \includegraphics[width=0.6\textwidth]{diagram}
  \caption{Processing pipeline}
\end{figure}

Damming floats: \FloatBarrier and \clearpage

The most maddening case is a figure that will not fit inside its own section and spills into the next one. When Figure 3 of Section 2 surfaces halfway through Section 3, the reader loses their place. The remedy is \FloatBarrier from the placeins package, written by Donald Arseneau and released to the public domain. To fence floats off by section, put it before each \section, or load \usepackage[section]{placeins} and it is inserted at the head of every \section for you.

One received idea needs correcting here: “\FloatBarrier does not break the page.” That is wrong. Read the placeins source and you find that \FloatBarrier issues a \newpage and calls itself again for as long as floats remain pending, falling back to \clearpage if they still will not clear. In a real run, a barrier crossed while a large [b] figure is outstanding puts the figure on the next page and resumes the text on the page after that — two page breaks. It leaves the page alone only when nothing at all is pending. The real distinction, then, is not “breaks the page or not” but “breaks unconditionally (\clearpage) versus breaks only when it must (\FloatBarrier)”.

latex
\usepackage{placeins}          % or [section] to barrier every \section
\usepackage{afterpage}
% ...
\section{Experiment}
% ... figures and tables ...
\FloatBarrier                  % nothing may cross this line
\section{Discussion}

% flush pending floats at the END of the current page, not right here
\afterpage{\clearpage}

When you want the effect of \clearpage but cannot afford a page break right here, the afterpage package supplies \afterpage{\clearpage}. It runs the \clearpage once the page currently being built has ended naturally, so no hole opens in the middle of your text. A more local tool is \suppressfloats[t], which says “no more floats at the top of this page” — and it is exactly what the [section] option of placeins uses internally, right after a heading. Note that [section] is quite strict by default: it forbids a float even from rising above the start of its section. The [above] and [below] options relax that.

The float-placement parameters: why LaTeX says it will not fit

The answer to “it should fit at the top, so why doesn't it?” is usually the placement parameters. LaTeX keeps a set of fractions and counts governing how much of a page it will surrender to floats, and in the article class the defaults are \topfraction = 0.7, \bottomfraction = 0.3, \textfraction = 0.2, \floatpagefraction = 0.5, with topnumber = 2, bottomnumber = 1 and totalnumber = 3. So a figure taller than 70% of the text height can never go at the top, by any route. If its specifier says only [t], it has nowhere to go and is pushed back indefinitely.

ParameterDefault in articleWhat it governs
\topfraction0.7Largest share of a page top that floats may occupy
\bottomfraction0.3Largest share of a page bottom that floats may occupy
\textfraction0.2Smallest share of a text page that must remain text
\floatpagefraction0.5Minimum fill needed before a float-only page is made
topnumber2Most floats allowed at the top of a page
bottomnumber1Most floats allowed at the bottom of a page
totalnumber3Most floats allowed on one page in total
\dbltopfraction0.7Share of a page top a two-column figure* may occupy

Change the fractions with \renewcommand{\topfraction}{0.85} and the integers with \setcounter{totalnumber}{5}. Raising \topfraction while lowering \textfraction lets more floats sit at the top and cuts down on “won't fit, push it back” evictions. The ! in [htbp] is in effect the one-shot local version of this tuning. Two-column layouts have their own values, and figure* obeys \dbltopfraction. One fact matters more than the numbers here: a two-column figure* can only go at t or p. LaTeX has no bottom list for full-width floats at all, and their default specifier is tp. Write \begin{figure*}[hb] and you get no warning whatever — it is quietly sent to the top of a page.

Too many unprocessed floats: the limit is 52, not 18

When the queue overflows you get ! LaTeX Error: Too many unprocessed floats. The widely repeated figure of “18 floats maximum” is out of date. latex.ltx does allocate eighteen boxes, \bx@A through \bx@R, but where e-TeX is available — which is every engine in use today — it goes on to add \bx@S to \bx@Z and \bx@AA to \bx@ZZ, for a total of 52. The extension arrived in the LaTeX release of 2015/10/01. Line up floats that genuinely cannot be placed and the error appears on the fifty-third, precisely.

The error does not mean you must delete figures. \extrafloats{n}, added in the same era, allocates more boxes from the preamble; in testing, a document that overflowed at 52 stopped complaining the moment \extrafloats{40} was added. But a shortage of boxes is usually a symptom rather than a cause. A document that overflows is normally hoarding floats that cannot be placed: a figure taller than 70% of the text height whose specifier says only [t], or a run of floats with so little text between them that no page break ever occurs. Widening the specifier to [htbp] and dropping an occasional \clearpage to flush the queue is the shorter road to a real fix. Related to this, LaTeX Warning: Float too large for page by ...pt means “this one does not fit on a page, so I have exiled it to a page of its own” — your cue to shrink the figure or change the paper size.

latex
% loosen the layout rules for the whole document
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\renewcommand{\floatpagefraction}{0.75}
\setcounter{totalnumber}{5}

% allocate 40 more float boxes on top of the built-in 52
\extrafloats{40}

Setting two figures side by side

A float does not care what it contains, so putting two figures side by side is just a matter of making two boxes inside one figure. In bare LaTeX that means minipage, an environment that builds a “little page” of a width you choose. Place two of them with \hfill — a stretchable horizontal space — between, and the slack is pushed outward so they hug the margins. Make each a shade under half the text width; 0.48\textwidth is the usual figure. Let the total exceed \textwidth and you get an Overfull \hbox and the second box drops to the next line.

latex
\begin{figure}[htbp]
  \centering
  \begin{minipage}{0.48\textwidth}
    \centering
    \includegraphics[width=\linewidth]{left}
    \caption{Left panel}      % its own number
    \label{fig:left}
  \end{minipage}
  \hfill
  \begin{minipage}{0.48\textwidth}
    \centering
    \includegraphics[width=\linewidth]{right}
    \caption{Right panel}     % a second, separate number
    \label{fig:right}
  \end{minipage}
\end{figure}

Inside each minipage, \linewidth means the width of that minipage, so \includegraphics[width=\linewidth] fills the box exactly. Because each minipage here carries its own \caption, the two become “Figure 1” and “Figure 2” with separate numbers. To make them (a) and (b) of a single figure you want the subcaption package, which the companion page handles. And when a two-column layout needs a figure spanning the full page width, use figure* (or table*) — remembering that, as above, it can only land at the top of a page or on a float page.

Wrapping text around a figure with wrapfig

For the magazine-style layout where text runs alongside a small figure, use the wrapfigure environment (or wraptable) from the wrapfig package — also by Donald Arseneau, the author of placeins. It takes four arguments, two of them required: {r} is which side to put it on, and the final {0.4\textwidth} is the width of the figure. The optional [12] is the number of lines to wrap, and the optional [34pt] is the overhang, how far the figure juts out past the text block. The placement letters come in pairs: lowercase pins it in place, uppercase lets it float.

latex
\usepackage{wrapfig}
% [lines]{side}[overhang]{width}
\begin{wrapfigure}[12]{r}[34pt]{0.4\textwidth}
  \centering
  \includegraphics[width=0.38\textwidth]{portrait}
  \caption{Portrait}
\end{wrapfigure}
LetterSideNotes
r / Rrightlowercase r pins it here, uppercase R lets it float
l / Lleftlowercase l pins it here, uppercase L lets it float
i / Iinner (binding side)alternates between left and right pages in twoside documents
o / Oouter (fore edge)alternates between left and right pages in twoside documents

In the example, a figure 0.4\textwidth wide sits to the right of the text, the following 12 lines wrap around its left, and [34pt] lets it jut into the right margin. Omit the line count and wrapfig estimates it from the height of the figure; when the estimate is off the wrap goes ragged, so stating it explicitly is the quick fix. wrapfig is a temperamental package, though, and its own manual limits where it may be used.

  • Do not use it inside a list, or immediately before or after one. Putting it in or beside itemize, enumerate or description breaks it.
  • Do not let it straddle a page break. Place it so the wrap does not split across two pages; stay away from page boundaries.
  • Do not wrap headings or displayed equations. Only ordinary running text should flow around it.
  • Start it at a paragraph boundary, not mid-paragraph. Inside a minipage or parbox, make sure the wrap finishes before the group does.

When the wrap misbehaves, narrowing the figure a little, stating the line count, or moving the start by one paragraph will usually settle it. If it still refuses, dropping wrapfig for an ordinary float ([htbp], above or below the text) tends to give a more readable page in the end. Once you have decided where a figure lands, the next job is giving it a number and a description.