Controlling LaTeX Floats

Introduction

One of the most frustrating features of LaTeX is its insistence on moving figures and tables (and other “floating matter”) to unexpected locations. However, there is a way to get some control over this problem.

It turns out that the main cause of the trouble is an extremely stupid choice of defaults for the float mechanism in LaTeX. Fortunately, these defaults are not hard-wired. They're set by the values of various parameters in the startup file used by LaTeX. That means you can just reset the ill-chosen values to something that gives more reasonable behavior.

Once these changes are made, the addition of an [htp] option to commands like \begin{figure} and \begin{table} — which is needed to override another set of ill-chosen defaults — will usually put figures and tables where you could reasonably expect them to appear in the formatted document.

Why there is a problem

Perhaps its useful at this point to delve just a bit into the mechanism LaTeX uses to determine where a float goes.

There are several integer-valued registers (called counters in TeX jargon) that limit the number of floats on a page: the number at the top, the number at the bottom, and the total. In addition, there are limits on the fraction of a page that can be occupied by floats — again, at the top and bottom separately, as well as the page as a whole.

If there are too many floats to fit on a page, LaTeX pushes them on to the next page, and the next; eventually, floats may end up at the end of the document. If the [p] option has been provided to individual figures and tables, they may be pushed together onto a “float page” that has no text. But even here, the defaults are stingy about the amount of space taken up.

The result is often that some individual float is too big to go anywhere, and so migrates to the end of the document. Unfortunately, the rule that says all figures must appear in sequential order (and a similar rule for tables) means that the single offender sweeps away everything that should follow it.

These parameters are discussed in detail on pp. 199–200 of the LaTeX Reference Manual (Lamport's book).

Undoing the dumb defaults

The default values that cause so much trouble are set in the class file that's invoked by the argument of the \documentclass statement at the beginning of your *.tex file. (For example, if that argument is article, the file that's called in is /usr/share/texmf/tex/latex/base/article.cls.)

To override the values that cause the offensive behavior, you use the \setcounter{} command to reset integer values, and \renewcommand{} to reset floating-point values. Like this:

% Alter some LaTeX defaults for better treatment of figures:
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    %   General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9}	% max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8}	% max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9}	% fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07}	% allow minimal text w. figs
    %   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7}	% require fuller float pages
	% N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7}	% require fuller float pages

	% remember to use [htp] or [htpb] for placement

These values can be reset in the preamble of your LaTeX source file; any place before the \begin{document} will do.

A remark about the [htp] argument

Though it's tempting to hope that [htp] gives preference to the [h] (i.e., “here”) option, it doesn't work that way. The arguments in brackets tell LaTeX where it's possible to put the float; their order is unimportant. If you're willing to have floats at the bottom of a page, as well as the top, use [htpb].

Putting an exclamation mark in the list of placement options makes LaTeX ignore all the constraints but \topfraction, \bottomfraction, and the ones with floatpage in their names.

The default, [tbp], omits [h], which is not usually what you want. (But note that many journal and book publishers may insist on the [tpb]choices alone.)

If you find that liberal values of the float parameters still are causing trouble, you can try forcing a float page with \clearpage to disgorge the accumulated blockage. If you don't want to force a pagebreak, use the afterpage package and tell LaTex  \afterpage{\clearpage}, which should force a float page when the current page comes to an end. If floats continue to pile up at the end, you probably have one too big to fit on a page; try reducing its size.

Run  texdoc fancyhdr  to read a good discussion of float placement. You may even need to use the float package, in extreme cases.

 

Copyright © 2005, 2006, 2010 Andrew T. Young


Back to the . . .
LaTeX-to-PDF conversion page

or the LaTeX top page

or the alphabetic index

or the website overview page