The afterpage package^{∗}

David Carlisle carlisle@cs.man.ac.uk

1995/10/27

This package implements a command, \afterpage, that causes the commands specified in its argument to be expanded after the curent page is output.^{1}

1. Sometimes L^{A}TEX’s float positioning mechanism gets overloaded, and all floating figures and tables drift to the end of the document. One may flush out all the unprocessed floats by issuing a \clearpage command, but this has the effect of making the current page end prematurely. Now you can issue \afterpage{\clearpage} and the current page will be filled up with text as usual, but then a \clearpage command will flush out all the floats before the next text page begins.

2. An earlier mechanism to help with float placement was the optional argument [H] (meaning HERE!) which was originally added to the standard floating environments by here.sty, and is now provided by float.sty. However some [H] users have commented that they did not really mean ‘Here!’ They actually wanted ‘Somewhere close’. This can now be achieved by

\afterpage{\clearpage\begin{figure}[H] . . . \end{figure}}

This ensures that the figure is at the top of the next page. (The \clearpage stops any other figures drifting past the [H] figure.)

3. Floating longtables. longtable.sty provides the longtable environment, a multi-page version of tabular. Many longtable users have told me that it is difficult to set the text surrounding the long table, and that they wanted a ‘floating’ version. As, presumably, longtables are long, they are probably too large to hold in memory, and float in the way that the table environment is floated, however if the table is in a separate file, say ltfile.tex, you can now use one of:

\afterpage{\clearpage\input{ltfile}}
\afterpage{\clearpage\input{ltfile}\clearpage}.

The first form lets text apear on the same page as the end of the longtable, the second ensures that the surrounding text starts again on a new page.

∗This file has version number v1.08, last revised 1995/10/27.

1This is really a pre-release, to see whether people like the idea of a command like this. This implementation is not particularly robust. This implementation does not work in two column mode, and can get ‘confused’ by L^{A}TEX’s floating environments.