7.2 Float placement control

In the previous section LaTEX’s basic algorithm for placing floats was discussed. We now look at a number of packages that alter or extend this algorithm or otherwise help you in controlling its behavior further.

The fewerfloatpages package improves on LaTEX’s standard algorithm, and it is recommended to always load it if you use floats in your document. The placeins package also helps with the placement by introducing a float barrier like , but without forcing a new page.

The afterpage package is a bit different and has limitations (and according to its author should not exist in the first place), but there are cases where it is extremely useful, which is why we describe it here.

Finally, we discuss the endfloat package that alters the algorithm so that all floats appear at the very end of the document by design (and not by mistake). Obviously that package should be loaded only if such a design is wanted.

7.2.1 fewerfloatpages - Improving LaTeX’s float algorithm

As discussed above, LaTEX’s float algorithm has the tendency to produce fairly empty float pages, i.e., pages containing only floats but with a lot of free space remaining that could easily be filled with nearby text. There are good reasons for this behavior; nevertheless, the results look unappealing, and in many cases documents are unnecessarily enlarged. To resolve this problem the fewerfloatpages package provides an extended algorithm that improves on this behavior without the need for manual intervention by the user.

Why does the current algorithm have these problems? To some extent, because it offers only global parameters that need to fit different scenarios, and thus settings that are suitable when many floats need to be placed result in suboptimal paginations in document parts that contain only a few floats, and vice versa. To overcome this problem, either one can try to develop algorithms with many more configurable parameters that act differently in different scenarios or one can let the algorithm follow a main strategy, configurable with only a few parameters (like today), but monitor the process and make more local adjustments and corrections depending on the actual outcome of that base strategy and additional knowledge of the actual situation in a given document part. This is the approach taken by the extension implemented in this package.

7.2.2 placeins - Preventing floats from crossing a barrier

Standard LaTEX already implements a float barrier called . Floats on either side never appear on the other. It works by first placing all deferred floats, if necessary by generating float pages, and then starting a new page. While this is suitable to keep floats within one chapter (because chapters typically start on a new page), there are cases where one would wish for a less intrusive barrier, i.e., one that works without forcing a new page or is partially porous.

This functionality is offered by Donald Arseneau’s placeins package, which implements a command that places all deferred floats without introducing a page break. This approach is, for example, useful if you want to ensure that all floats that belong to a section are placed before the next section starts. Through package options, you can alter the behavior to allow for floats to migrate from one side to the other, as long as they still appear on the same page.

You could, for example, redefine the sectioning command yourself and introduce the command by using the \titleformat declaration from the titlesec package (see Section 2.2.7), as shown here:

7.2.3 afterpage - Taking control at the page boundary

The afterpage package (by David Carlisle) implements a command that causes the commands specified in its argument to be expanded after the current page is output. Although its author considers it “a hack that not even always works” (for example, fails in twocolumn mode), it has a number of useful applications in the cases where it does work.

Sometimes LaTEX’s float positioning mechanism gets overloaded, and all floating figures and tables drift to the end of the document. You may flush out all the

unprocessed floats by issuing a command, but this tactic has the effect

of making the current page end prematurely. The afterpage package allows you to issue the command . It allows the current page to be filled with text (as usual), but then a command flushes out all floats

before the next text page begins. With the multipage longtable environment (see Section 6.4.2), you can experience problems when typesetting the text surrounding the long table, and it may be tables

useful to “float” the longtable. However, because such tables can be several pages long, it may prove impossible to hold them in memory and float them in the same way that the table environment is floated. Nevertheless, if the table markup is in a separate file (say ltfile.tex), you can use the following declaration:

7.2.4 endfloat - Placing figures and tables at the end

Some journals require figures and tables to be separated from the text and grouped at the end of a document. They may also want a list of figures and tables to precede them and potentially require markers indicating the original places occupied by the floats within the text. This can be achieved with the endfloat package (by James Darrell McCauley, Jeffrey Goldberg, and more recently, Axel Sommerfeldt), which by default extracts figures and tables from within the document and places them at the very end. With appropriate configuration settings it can do the same for other float types if they are provided by packages such as float, newfloat, etc.

For its default task of managing figures and tables the endfloat package features a series of options to control the list of figures and tables, their section headings, and the markers left in the text at the call-out point of the figure or table float. A list of available options1 follows:

figlist/nofiglist Produce (default) or suppress the list of figures.

fighead/nofighead Produce or omit (default) a section heading before the collection of figures. The section headings text is given by and defaults to the string “Figures”.

figuresfirst figuresonly nofigures Put all figures before tables (default).Only manage figures but not tables as endfloats.Do not handle figures as endfloats.

There are also a few package options for jointly customizing all float types— these also act on any additional float type that is declared in the document:

lists/nolists Produce or suppress the list of floats (figures, tables, etc.).

heads/noheads Produce or omit a section heading before each float collection.

markers/nomarkers Place (default) or omit markers in text to indicate the call-out position of floats.

disable Make the package a no-op; i.e., if used, all other options or declarations are ignored. The reason for this option is that one often needs both a version for the journal (with endfloats) and a version with the floats in their correct places, and by temporarily adding this option, the latter can be easily achieved without other adjustments.

By default, the package indicates the original position of a float within the text