Latest news 2021-06-05: New blog post: Dickimaw Books Site Account.

7.4 Sub-Floats

Some floats have sub-floats within them. For example, a figure may contain several sub-figures, each of which requires a caption. The simplest way to do this is to use the subcaption package that provides the subfigure and subtable environments:



Within these environments, you can use \caption to create a sub-caption. (In addition to the main \caption for the containing figure or table environment.)


The subcaption package requires the caption package, but doesn't automatically load it, so you'll need to load both:



This is very similar to the side-by-side figures example from §7.1.1. Side-By-Side Figures.

\caption{Two Shapes}

This produces Figure 7.5. Elsewhere in the document, the figure and its components can be referenced:

Figure~\ref{fig:shapes2} shows some shapes. Figure~\ref{fig:rectangle} shows a rectangle and Figure~\ref{fig:circle} shows a circle.

which produces the following text:

Figure 7.5 shows some shapes. Figure 7.5a shows a
rectangle and Figure 7.5b shows a circle.

You can also reference just the sub-float using


which is analogous to \ref, but only displays the sub-float number without the number associated with its containing float.


Figure~\ref{fig:shapes2} shows: (\subref{fig:rectangle}) a rectangle and (\subref{fig:circle}) a circle.


Figure 7.5 shows: (a) a rectangle and (b) a circle.

Figure 7.5: Two Shapes
rectangle.png circle.png
(a) Rectangle (b) Circle


The subfigure labels (a, b, etc) should typically be in italic [17]. This can be achieved with the caption package using:


where <format-name> is the name for this new format and <code> is the code used to format the label where #2 gets replaced by the reference number.

Once you have defined a new format, you can then use


to switch to that new format. For subfloats, <type> needs to be set to sub. The second argument <options> is a <key>=<value> comma-separated list. The key that sets the format is labelformat. (For further details about both \DeclareCaptionLabelFormat and \captionsetup, see the caption package documentation.)

For example, to create a format called em-noparens that displays the number in an emphasized font without parentheses:


Now switch to that new format:


Note that this only changes the caption label format. It doesn't affect the font used by \ref or \subref. For \ref, you can use the fncylab package, which provides the command:


Within <defn>, use #1 to represent the subfigure value and use \thefigure for the encapsulating figure number. For example:




will produce

7.5a (the letter a is emphasized)

Unfortunately, this doesn't work for \subref. Instead you will have to do, for example, the following in the text:


If you want to add parentheses, the above can be modified to:


For \subref, you will have to do, for example, the following in the text:


Exercise 18: Creating Sub-Figures

Download the image files rectangle.pdf and circle.pdf (or create your own images) and add Figure 7.5 to your document. You can download or view the solution.

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs