7.4 Controlling the float caption
When you want to explain what is shown in your floating environment (figure or table in standard LaTEX), you normally use a
ommand. After introducing the basic syntax and explaining the (low-level) interfaces available with standard LaTEX, this section describes the powerful caption package, which offers a large number of customization possibilities for adjusting the caption layout to your needs. As shown in the examples, it can be combined with all other packages described in this chapter.
The section concludes by examining the subcaption package, which introduces substructures for float objects. Another package that introduces the concepts of side captions and works in concert with caption and subcaption is discussed later in Section 7.5.1 on page 560.
7.4.1 caption - Customizing your captions
Axel Sommerfeldt developed the caption package1 to customize the captions in floating environments. It not only supports LaTEX’s standard figure and table environments, but also interfaces correctly with the command and the sidewaysfigure and sidewaystable environments of the rotating package. It works equally well with most of the other packages described in this chapter (see the original documentation for a complete compatibility matrix).
Like many packages these days, the caption package uses the extended option concept (based on the keyval package), in which options consist of a key and a value separated by an equal sign. In most cases there exists a default value for an option; thus, you can specify just the key without a value to produce this default behavior.
The customization possibilities of the caption package cover (nearly) all aspects of formatting and placing captions, and we introduce them below. For those users who need even more customization, the package offers an interface to add additional key values (representing special formatting).
Using package options allows us only to set defaults for all float captions regardless of their type. The caption package therefore also supports setting these options/keys through declarations. This way you can provide settings on a per type basis (if necessary) and also overwrite the default settings for individual floats in the document if that becomes necessary.
7.4.2 subcaption - Substructuring floats
The subcaption package (by Axel Sommerfeldt) allows the manipulation and reference of small, “sub” figures and tables by simplifying the positioning, captioning, and labeling of such objects within a single float environment. If desired, subcaptions associated with these subfloats can appear in the corresponding list of floats (e.g., the list of figures). In addition, a global caption can be present. If hyperlinks are enabled in the document, cross-references correctly link back to their origin, a feature not available in the subfig package (by Steven Cochran) that for a long time dominated this type of layout.
In this section we describe subcaption because it is closer linked with the caption package, does not have some of the restrictions of subfig (most notably the problem with the hyperref support), and offers more flexibility and features. There are, however, cases where it might be appropriate to resort to subfig, for example, when using a document class that conflicts with the caption package, because this means subcaption cannot be used either.
The syntax of the two packages is not identical but is similar enough that it is easy to convert a document from one to the other. For example, the dominant command in subfig is , which corresponds to a restricted version of subcaption’s , except that in the latter the caption argument is mandatory while it is optional with .