Stage 5 · Figures, tables and bibliography 37 / 48 ≈ 18 min read

LaTeX Float Positioning: htbp, the float Package and Escapes

A float is a box on a list, and the list is drained by a page-breaker that tests four numbers you can change. This page follows one float from \begin{figure} to the printed page — the deferred list, the top and bottom slots, the float page — then shows what h t b p ! really permit, which kernel parameters decide the outcome, and why [H] is usually the wrong escape.

    A float is a box on a list

    When LaTeX meets \begin{figure}[htbp] it does not place anything. It opens a box (\@currbox, taken from the pool of free boxes \@freelist), pours the material into it, and files the box on a list: \@deferlist for ordinary floats, \@dbldeferlist for the column-spanning figure* and table*. That is all the command does. Everything after that happens in the output routine, when a column is being assembled.

    At the start of every column, the kernel asks \@tryfcolumn whether the deferred boxes can fill a whole column of floats; if not, \@startcolumn fills the top slots and the bottom slots from \@deferlist, records them in \@toplist and \@botlist, and shrinks the room left for text (\@colroom) accordingly. Text is then collected, and \@makecol glues the top floats, the text and the bottom floats into one vertical box that \@outputpage ships out, using \floatsep between floats and \textfloatsep between a float and text.

    Two consequences explain almost every "my figure moved" complaint. First, a float can only ever be placed at or after the point in the source where it appears: the box does not exist before the command is read, so LaTeX cannot move it backwards to keep company with an earlier sentence. Second, once a float is deferred it competes with the other deferred floats for the slots on the next page, and the winner is decided by the numeric tests in the next section, not by your placement letters.

    It is worth remembering what a float is for. TeX refuses to break a page through a float, because a diagram split in half is worse than a diagram moved one page down. That guarantee is the price you pay for the movement, and it is also exactly the guarantee [H] throws away.

    The four slots a float may occupy on a page, the fractions that bound them, and the lists the output routine drains them from ONE TEXT PAGE, H = textheight (220 mm ON A4 ARTICLE) top slot 1 (t) counted by topnumber top slot 2 text h placement: the box sits in here, surrounded by intextsep, and counts against totalnumber text left must be at least theta H bottom slot (b) bottomnumber, botroom = beta H toproom = tau H tau = topfraction = 0.7 so 154 mm of float at the top botroom = beta H = 66 mm A FLOAT PAGE (p) no text at all made only when the deferred boxes reach fpmin = rho H rho = floatpagefraction = 0.5 in article.cls stack spacing: fptop, fpsep, fpbot THE LISTS @freelist empty boxes to fill @deferlist waiting for the next column break @dbldeferlist figure* and table* top of a page only @toplist chosen for this page @botlist chosen for this page @midlist the h survivors combined by @makecol, shipped by @outputpage Escape hatches act at different points: [!ht] changes the permissions of one box, FloatBarrier drains the queue at a point in the text, clearpage ships out everything and starts a new page, and [H] removes the box from this pipeline entirely.
    The four slots a float can occupy, and the lists the output routine drains them from at every column break.

    What h, t, b, p and ! actually permit

    The kernel documents the letters as a set of permissions, not a priority order: h = at the current location in the text, t = at the top of a text page, b = at the bottom of a text page, p = on a separate float page. Writing [htbp] says "any of these four is acceptable"; LaTeX does not try them left to right and it does not prefer the first letter.

    h is the weakest of the four in practice, because it has to pass a tight test at the moment the float is read: the box must fit in the space left in the column, leaving at least \textfraction of the column for text. A figure more than about half a column tall almost never satisfies that in the middle of a paragraph, which is why the classic message exists: LaTeX Warning: `h' float specifier changed to `ht'. LaTeX is telling you it dropped your request and is trying the top slot instead.

    ! means "ignore the numeric float parameters for this float" — the fractions \topfraction, \bottomfraction and \textfraction stop being tested for this box. It does not buy you a slot that is physically full, and it has no effect on p, which is governed by its own \floatpagefraction test. [!ht] is therefore "here if it fits at all, else the top of this page", which is a reasonable request; [h!] is a mood.

    The default for a float class lives in \fps@figure and \fps@table: with no optional argument, \begin{figure} uses whatever those macros hold (in the standard classes, tp for figures and tp for tables, so a bare \begin{table} is already allowed to float to the next page). If you want the whole document to change its default, \renewcommand{\fps@figure}{htbp} is the mechanism — there is no public \floatplacement in the kernel, and packages that advertise such a command are just wrapping this macro.

    h_{\mathrm{float}} > H_{\mathrm{remaining}} \;\Longleftrightarrow\; \text{the h specifier is widened to ht}
    h_{\mathrm{float}} > H_{\mathrm{remaining}} \;\Longleftrightarrow\; \text{the h specifier is widened to ht}
    The reason [t] beats [h] in dense papers is not taste: the top slot of the next page is the only one that reliably has room for a full-height figure.

    The numbers that decide it

    Every placement test compares a height with a fraction of the column height H (the kernel's \@colht, equal to \textheight at the start of a column). The top slots together may take \topfraction⁠×⁠H; the bottom slots \bottomfraction⁠×⁠H; and at least \textfraction⁠×⁠H must be left for text. Counters cap the population: topnumber, bottomnumber and totalnumber (which includes any in-text float).

    A float page is a different test. The kernel computes \@fpmin = \floatpagefraction × H and \@tryfcolumn only agrees to fill a page with nothing but floats if the boxes on the deferred list add up to at least that much. This is why a single lonely figure can sit in the queue for two pages: article.cls sets \floatpagefraction to 0.5, so one 60 mm figure is not enough to justify a page of nothing else.

    The defaults are set by the class, not by the kernel, and the standard article values are conservative in a way that suits 1986 books rather than 2026 papers: topnumber 2, \topfraction 0.7, bottomnumber 1, \bottomfraction 0.3, totalnumber 3, \textfraction 0.2, \floatpagefraction 0.5. Since \textfraction is 0.2, any float taller than 80 percent of the column cannot go at the top of a text page at all, which surprises everybody once.

    The fix is a block of preamble lines, not a fight with individual placement letters: raise \topfraction to 0.85, drop \textfraction to 0.07, raise \floatpagefraction to just under \topfraction (a float page and a top slot compete for the same boxes, so keep them consistent), and raise totalnumber to 5. Listing 0 below is that block, with the stock values in comments. Set \floatpagefraction higher than \topfraction and you get the notorious LaTeX Warning: Text page 5 contains only floats plus a page of white space.

    R_{\mathrm{top}} = \tau H,\quad R_{\mathrm{bot}} = \beta H,\quad H_{\mathrm{text}} \ge \theta H
    R_{\mathrm{top}} = \tau H,\quad R_{\mathrm{bot}} = \beta H,\quad H_{\mathrm{text}} \ge \theta H
    Symptom and cause, matched: Too many column floats means totalnumber is exhausted, and a float stuck in the queue for pages means \floatpagefraction or \topfraction is doing exactly what you set it to.
    \documentclass[a4paper,10pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage{graphicx,booktabs,caption}
    \usepackage{placeins}       % \FloatBarrier; option "section" = barrier per section
    
    % ---- the numbers LaTeX tests against (article.cls defaults in brackets)
    \setcounter{topnumber}{3}            % [2]  floats allowed at the top
    \renewcommand{\topfraction}{0.85}    % [.7] fraction of the column they may take
    \setcounter{bottomnumber}{2}         % [1]  floats allowed at the bottom
    \renewcommand{\bottomfraction}{0.7}  % [.3]
    \setcounter{totalnumber}{5}          % [3]  floats on one page, h included
    \renewcommand{\textfraction}{0.07}   % [.2] minimum fraction that must be text
    \renewcommand{\floatpagefraction}{0.75} % [.5] how full a float page must be
    
    % two-column spans
    \setcounter{dbltopnumber}{2}
    \renewcommand{\dbltopfraction}{0.85}
    \renewcommand{\dblfloatpagefraction}{0.75}
    
    % the gap a float leaves around itself
    \setlength{\floatsep}{14pt plus 4pt minus 3pt}
    \setlength{\textfloatsep}{14pt plus 4pt minus 3pt}
    \setlength{\intextsep}{14pt plus 4pt minus 3pt}
    
    \captionsetup{font=small,skip=6pt}
    
    \begin{document}
    \section{Results}
    As Figure~\ref{fig:one} shows\dots
    \end{document}

    Keeping a float near its text: the honest tools

    \FloatBarrier, from the placeins package, is the tool people want without knowing its name: it forbids any float to appear after this point that was not already placed, i.e. it drains the deferred list before the barrier. Put one at the end of each section — \usepackage[section]{placeins} inserts one automatically at every \section — and figures stop wandering into the next chapter. It cannot create room, so a barrier can leave a large gap at the bottom of the page it flushes; that is the intended trade, and it is a far better one than a figure appearing three pages from its first mention.

    \clearpage is stronger: it ends the page and sends every remaining float to a float page. It is the right thing at the end of a chapter, and it is what LaTeX itself runs before a \tableofcontents or a \bibliography. \afterpage{\clearpage} (package afterpage) is the subtle version: it lets the current page finish as it is and flushes everything at the next page break, which is the standard answer to "this page is half empty and the figure is stuck in the queue".

    \suppressfloats[t] and \suppressfloats[b] are the narrow instruments: they close the named slot for the rest of the current page. Use it when a page has a top float that already fills the visual budget and a second one would look absurd. It is local, so it belongs right after the material you want protected, not in the preamble.

    \enlargethispage{2\baselineskip} buys physical room on the current page, which is sometimes what actually blocks an h placement: no rule was violated except the height budget. Combine it with [!ht] and remember it affects one page only and does not survive a reflow — treat it as a final-proofing tool and comment the reason into the source.

    Source order versus printed order: a float can only move forwards, so a figure written between two paragraphs may land at the top of the next page SOURCE, TOP TO BOTTOM para 1 ... begin{figure}[htbp] fig:A Figure A, 92 mm tall para 2 ... begin{table}[htbp] tab:X Table X, 24 mm tall section{Discussion} FloatBarrier (automatic with placeins option section) begin{figure}[H] fig:B Figure B, pinned PAGE 1 AS SHIPPED top slot: Table X moved up here paras 1 and 2 Figure A does not fit in the room left after textfraction is served, so h fails and the box is deferred warning: h changed to ht Discussion, first lines nothing may pass the barrier Figure B: exactly where written, and unbreakable PAGE 2 AS SHIPPED top slot: Figure A taken from @deferlist at the start of the new column text continues Discussion is now two paragraphs away from the figure it cites, which is why you refer to it as Figure~\ref{fig:A} never as "the figure above" Moving a float earlier in the source is the one edit that always changes the outcome: a float is only ever allowed to travel forwards from where it was written.
    Where each escape acts: the barrier drains the queue, clearpage ends the page, suppressfloats closes a slot, enlargethispage buys height.

    Why [H] is nearly always the wrong answer

    The float package's [H] specifier does not place a float. It typesets the material as ordinary, non-floating content at the exact point you wrote it, using a \par and a box. Because the box is built as one unit, the page breaker may not split it — which is the defining property of a float, so [H] is not "float but here", it is "not a float at all, and I accept the consequences".

    The consequences are specific and reproducible. If the material does not fit in the room left on the page you get an overfull \vbox and content that runs into the bottom margin or behind the footer; if the material is taller than a whole page it can simply be lost. Text before it is not stretched, so the paragraph above ends early and leaves a hole that no amount of \raggedbottom explanation will justify to a reviewer. And a document that uses [H] everywhere has, in effect, no float algorithm — every figure is then your responsibility, in every revision, on every page.

    The two cases where [H] is genuinely right: a single small graphic that is part of an argument and must sit between two paragraphs, and a listing of code or a table used as an example of itself inside a document about LaTeX. Even then, prefer \captionof from the caption package (or the light-weight capt-of): a centred box plus \captionof{figure}{...} gives you the number, the \label, the list-of-figures entry and a legal page break around the whole thing, with none of the float machinery in play.

    If the real complaint is "the figure should appear on the same page as the sentence that mentions it", the fix is usually the parameter block plus \FloatBarrier at the end of each section, not [H]. The older nonfloat package and the floatrow layer both attack the same problem from the float-code side rather than the "give up" side, and floatrow is the one that also gives you row-level control of caption placement and of two different float kinds side by side — note that floatrow and subcaption are not designed to be loaded together, so choose one system for grouped figures.

    \documentclass[a4paper]{article}
    \usepackage{graphicx}
    \usepackage{caption}      % provides \captionof
    \usepackage{float}        % provides [H]
    \usepackage{needspace}    % \needspace: only place it if room remains
    \usepackage{afterpage}    % \afterpage{\clearpage}
    \begin{document}
    
    % (a) Ask for here, but let the page breaker have the last word.
    \begin{figure}[!ht]
      \centering
      \includegraphics[width=0.6\textwidth]{curve}
      \caption{Preferred form: the bang ignores the fractions, not the page.}
      \label{fig:one}
    \end{figure}
    
    % (b) A barrier at the end of the section: nothing may float past it.
    \FloatBarrier
    
    % (c) No float at all: a centred box plus \captionof keeps the counter,
    %     the number, the LOF entry and a legal page break around it.
    \begin{center}
      \includegraphics[width=0.6\textwidth]{block2}
      \captionof{figure}{Pinned exactly here, and still called Figure 2.}
      \label{fig:pinned}
    \end{center}
    
    % (d) The float package's [H]: typeset as ordinary material, cannot break,
    %     so an over-tall [H] float walks into the bottom margin.
    \needspace{8\baselineskip}   % guard: move on if too little room is left
    \begin{figure}[H]
      \centering
      \includegraphics[width=0.9\textwidth]{wide}
      \caption{Exactly here, at the price of the page breaker.}
    \end{figure}
    
    \end{document}

    Two columns, spans, and the one-page delay

    A figure* or table* is a separate float class with its own list (\@dbldeferlist), its own counters (dbltopnumber) and its own fractions (\dbltopfraction, \dblfloatpagefraction). It may go at the top of a page or on a float page; the h and b letters are not honoured by the standard classes at all, so \begin{figure*}[htbp] is silently a [t] request.

    The delay is structural. A span float can only be placed on a page that is still being gathered, and the two-column output routine ships a page once both its columns are complete. A figure* announced while the left column of page 3 is being built cannot be inserted into page 3, so it lands at the top of page 4 — which is why the professional habit is to write the figure* one section earlier than the text that discusses it, and to refer to it by number rather than "the figure above".

    Bottom-placed spans are the one thing the kernel really does not support, and two packages exist to fix it: stfloats, which adds the bottom option for figure* and table*, and the more recent dblfloatfix, which patches top and bottom placement for spans more thoroughly. Either one is enough; do not load both, and re-check any float page in the back matter afterwards, because a span page is built by different code from a text page.

    In a one-column document a figure* is not an error but a trap: the starred environments are only meaningful when the class is running in two-column mode, and in a single-column article they degrade to ordinary floats with confusing placement. If you want "the width of the text block" you already have it — size the graphic, not the environment.

    \documentclass[twocolumn,a4paper]{article}
    \usepackage{graphicx}
    \usepackage{stfloats}       % allows bottom placement of figure* / table*
    \usepackage{dblfloatfix}    % alternative: fixes top/bottom spans in 2-column
    
    \setcounter{dbltopnumber}{2}
    \renewcommand{\dbltopfraction}{0.85}
    \renewcommand{\dblfloatpagefraction}{0.75}
    
    \begin{document}
    
    \section{Method}
    % A span float may go at the top of a page (or with stfloats, at the
    % bottom), or on a float page -- never "here" in the middle of a column.
    \begin{table*}[t]
      \centering
      \caption{Parameter estimates for all four rigs.}
      \label{tab:all}
      \begin{tabular}{lrrrr}
        A & B & C & D \\ \hline
        1 & 2 & 3 & 4
      \end{tabular}
    \end{table*}
    
    % If the span is announced in the left column of page 3 it lands on page 4,
    % because the page must be gathered before it can be shipped out.
    Table~\ref{tab:all} therefore appears one page later than you wrote it.
    
    \end{document}

    Spacing: the tuning that changes the look, not the place

    Five lengths govern what a placed float looks like once it has arrived. \floatsep is the glue between two adjacent floats, \textfloatsep the glue between a top or bottom float and the text, \intextsep the space above and below an in-text (h) float. All three are stretchable by design — 14pt plus 4pt minus 3pt — and they are the reason a page can look unbalanced rather than broken: the glue is doing what glue does.

    A float page has its own trio: \@fptop, \@fpsep and \@fpbot, which place the stack of floats on a p page. They default to a fill before, a stretchable glue between, and a fill after, so float pages are top-aligned; \setlength{\@fpbot}{0pt plus \fil} and friends are how you stop a page of three short figures from being spread over the whole sheet.

    Between a caption and its material sit \abovecaptionskip and \belowcaptionskip, and the caption package exposes them as skip= plus position=, font=, labelfont=, justification= and singlelinecheck=. Because \belowcaptionskip is small in the standard classes and captions below figures want a gap above, the classic "my caption is glued to the image" complaint is a one-line fix in the preamble rather than a \vspace pasted under every figure.

    Finally, the page as a whole: \flushbottom (the book default) stretches the glue on every page so that all columns end at the same height, which is exactly what turns a slightly-too-large float into visible rivers of white space between paragraphs. \raggedbottom — the article default — lets a page end short instead. On a float-heavy draft, switching between the two tells you immediately whether your problem is the float placement or the stretchability you allowed around it.

    \sum_{k=1}^{n} h_{k} + (n-1)s \;\ge\; \rho_{\mathrm{fp}}\,H \qquad (s = \text{float separation})
    \sum_{k=1}^{n} h_{k} + (n-1)s \;\ge\; \rho_{\mathrm{fp}}\,H \qquad (s = \text{float separation})
    Never fix a gap with \vspace inside a float: the float's height is what every test above compares against, so a manual skip changes where the float is allowed to go.

    The messages, and what to do about each

    LaTeX Warning: \`h' float specifier changed to \`ht'. Your h failed the fit test. Either accept it (that is what the letters mean), shorten the graphic, or raise \textfraction/\topfraction as in listing 0. Do not add a ! reflexively: the bang removes the fraction tests but cannot remove the room.

    ! LaTeX Error: Too many column floats. More floats are waiting than totalnumber permits in one column, typically because a \FloatBarrier or a \clearpage is holding boxes back. Raise totalnumber, allow p in the placement, or move the barrier.

    LaTeX Warning: Text page 5 contains only floats. The float page test passed but the page had nothing else on it: \floatpagefraction is too low relative to how much float material you have, or a ! forced a placement that the algorithm would have refused. Raise \floatpagefraction and stop forcing.

    Overfull \vbox reported "detected at position N in output routine" or "while shipping out page N". Something that is not breakable was inserted into the vertical list at page-builder time: an [H] float, a minipage taller than the page, or a \parbox in the wrong place. Replace the [H] with a [ht] float, or with \captionof outside any float if the position genuinely matters. And when a figure simply refuses to appear anywhere near its text, check the last section's trick first: a float written after the paragraph that mentions it can only ever go forward, so move the source — the one edit that always works.

    \theta H = 0.2 \times 220\,\mathrm{mm} = 44\,\mathrm{mm} \quad \text{of text still required}
    \theta H = 0.2 \times 220\,\mathrm{mm} = 44\,\mathrm{mm} \quad \text{of text still required}
    The whole debugging sequence: read the first message, not the last; check the parameter block once for the whole document; then move the float in the source. Never re-order the letters hoping for luck.

    Lesson cheat sheet

    One key line of code from each section — jump to it or copy it straight from here.

    Section Key code
    h_{\mathrm{float}} > H_{\mathrm{remaining}} \;\Longleftrightarrow\; \text{the h specifier is widened to ht}
    \documentclass[a4paper,10pt]{article}
    \documentclass[a4paper]{article}
    \documentclass[twocolumn,a4paper]{article}
    \sum_{k=1}^{n} h_{k} + (n-1)s \;\ge\; \rho_{\mathrm{fp}}\,H \qquad (s = \text{float separation})
    \theta H = 0.2 \times 220\,\mathrm{mm} = 44\,\mathrm{mm} \quad \text{of text still required}

    Common mistakes

    • Using [H] from the float package as a general policy. It is not a float, it cannot break across a page, and an over-tall one walks off the bottom of the sheet.
    • Treating [htbp] as a priority list. The letters are permissions; the order you write them in changes nothing except the message you get when h fails.
    • Forcing every float with [!h] and then adding \vspace{-2cm} inside the caption. The negative skip changes the float's height, which changes where the next float may go.
    • Raising \topfraction without raising \floatpagefraction, or setting the two in the wrong order, so a page of nothing but floats appears and Text page contains only floats shows up in the log.
    • Expecting figure* to honour h or b in a two-column document: spans go at the top or on a float page unless you load stfloats or dblfloatfix.
    • Putting the float after the paragraph that discusses it and then blaming LaTeX. Floats move forward only.
    • Loading floatrow together with subcaption and chasing the resulting caption errors: they are alternative systems for the same job.

    Questions about this lesson

    How do I keep a figure on the same page as the text that mentions it?
    Put the float in the source immediately after the paragraph that mentions it, ask for [!ht], and set the global limits once: topnumber 3, topfraction .85, textfraction .07, floatpagefraction .75, totalnumber 5. Then add \FloatBarrier at the end of every section so nothing floats past the heading. That combination keeps a figure on its page far more often than any per-figure trick.
    What does the H specifier do differently from h?
    h asks the float algorithm to place the box at the current position if it fits; if it does not fit, the float goes into the queue. H bypasses the algorithm and typesets the material as ordinary non-floating content, which means it will not break across a page and can overflow the bottom margin. H is a demand, h is a permission.
    What is FloatBarrier and do I need placeins?
    placeins defines \FloatBarrier, a point no float may pass: everything still deferred is placed before it, so figures stop drifting into the next section. Loading the package with the section option puts one barrier automatically at every \section. The kernel has no equivalent command; \clearpage is a much blunter tool that also ends the page.
    Why is my figure appearing two pages after I wrote it?
    Because it did not fit anywhere on the pages between, and the queue is drained in strict order at each column break. Either the figure is too tall for topfraction, or floatpagefraction is refusing to give it a page of its own. Raise the fractions, shrink the graphic, or move the float earlier in the source.
    How do I stop LaTeX putting a figure on a page of its own?
    Give it no permission to: drop the p from the placement list, so [ht] or [!ht] only. If it still arrives on a nearly empty page, the deferred queue is full; check totalnumber and consider \FloatBarrier so earlier pages absorb the backlog.
    Is there a way to place a caption without floating anything?
    Yes, and it is the cleanest answer when the position really matters: put the graphic in a center environment and use \captionof{figure}{...} from the caption package, or the smaller capt-of package. You keep the counter, the number, the cross-reference and the list-of-figures entry, and the page breaker may still split the surrounding text normally.

    Live playground: edit the LaTeX, see it render

    The preview updates as you type — break it on purpose to see how errors look.

    KaTeX error
    Try an example

    Keep reading

    Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.