7.3 Extensions to LaTeX’s float concept

By default, LaTEX offers two types of horizontally oriented float environments, figure and table. For many documents these prove to be sufficient; in other cases additional features are needed. In this section we now look at packages that extend this basic tool set to cover more complex cases.

The float package offers ways to define new float types and also provides one way to prevent individual floats from floating at all. A different approach to the latter problem is given by the caption package, which we briefly touch upon too.

We then discuss two packages, rotating and rotfloat, that allow the rotation of the float content, something that might be necessary for unusually large float objects. With a somewhat different approach this is also covered by the key/value packages discussed in Section 7.5 on page 560.

The final package in this section (wrapfig) deals with floats that are placed inside the galley with normal paragraph text flowing around them. Such objects look like ordinary floats, e.g., they can have a caption and are similarly formatted, but being placed next to their call-out they do not really “float” and thus may get out of sequence with ordinary floats that may get deferred and this way move past such in-line floats. A similar type of “nonfloating” floats are those that are placed into the margin. They are not discussed here but as part of Section 7.5.2.

Another type of extension, not discussed here but deferred to Section 7.5.1 on page 560, is that of full-page floats, where there is no room for the caption, so that it needs to be placed onto the facing page, turning the float effectively into a doublepage float. The package discussed there also offers some support for automatically producing floats that split their content and place it across two facing pages.

7.3.1 float - Creating new float types

The float package1 by Anselm Lingnau, which dates back to the nineties, improves the interface for defining floating objects such as figures and tables in LaTEX. It adds the notion of a “float style” that governs the appearance of floats. New kinds of floats may be defined using the command.

7.3.2 Captions for nonfloating figures and tables

An alternative to specifying the [H] option with the various float environments, as described in the previous section, is to define captioning commands that typeset and are entered into the “List of Figures” or “List of Tables” just like LaTEX’s standard figure and table environments. This functionality is provided by the caption package (discussed in more detail in Section 7.4.1).

7.3.3 rotating, rotfloat - Rotating floats

Sometimes it is desirable to turn the contents of a float sideways, by either 90 or 270 degrees. Because TEX is not directly capable of performing such an operation, it needs support from an output device driver. To be as device independent as possible, LaTEX encapsulates the necessary operations in the packages graphics and graphicx (see Section 8.1). One of the earliest packages that used this interface was the rotating package written by Sebastian Rahtz (1955–2016) and Leonor Barroca.1

The rotating package implements two environments, sidewaysfigure and sidewaystable, for turning whole floats sideways. These environments automatically produce page-sized floats, or more exactly column-sized floats (if used in twocolumn mode). Starred forms of these environments, which in twocolumn mode span both columns, exist as well.

By default, the floats are turned in such a way that they can be read from the outside margin, as you can see in the next example. If you prefer your floats to be always turned in the same way, you can specify one of the package options figuresright or figuresleft.

7.3.4 wrapfig - Inline floats, wrapping text around a figure

In TEX’s typesetting model, text is first broken into paragraphs on a vertically oriented galley (or scroll). Once enough material is collected in this way TEX invokes its output routine, which chops off the first part of the galley, attaches running headers and footers as specified, and outputs the result in the .dvi file. It then restarts collecting text and breaking it into paragraphs to refill the galley.

As a consequence of this processing model, it is relatively easy to implement a float mechanism in which floats span the full width of the page or at least the full width of individual columns. Unfortunately, it is nearly impossible to have floats that occupy only parts of a text column and have the text flow around them. The reason is that when the paragraphs are broken into lines, their final positions are not yet known. It is therefore impossible to direct the paragraph builder to leave holes for the float objects if a later part of the process decides on their final placement. In contrast, placing floats at the top or the bottom of a page (or column) only directs the output routine to chop off less material from the assembled galley without otherwise manipulating the galley content.

Because of this processing model, the production of inline floats with text flowing around the float object has to take place during the paragraph-generating phase. The best outcome that packages can currently achieve is to ensure that the inline floats do not fall off the page (by measuring the amount of material already assembled on the galley to decide whether there is enough space to fit in the inline float with its surrounding paragraph(s)).

Such an algorithm is, for example, implemented by Donald Arseneau’s wrapfig package. Because the package’s inline floats only “float” very little in comparison to standard floats, mixing both types can result in the float numbering getting out of sequence. There are other packages offering this kind of functionality, but all of them have one or the other problem and often leave the placement decisions completely to the user because the automatic solution comes out wrong in many cases so that it is not worth supplying it in the first place. The wrapfig package supports figures and tables and offers some support for automatic placement, which works reasonably well.

The package wrapfig defines the wrapfloat, wrapfigure, and wraptable environments. These environments allow one to typeset a narrow float at the edge of some text and then make the text wrap around it. All three produce captions with the standard caption layout for floats. Although the environments have some limited ability to “float”, no provision is made to synchronize them with regular floats. Thus, one must be aware that they may be printed out of sequence with standard floats.