How does one create, caption, label and refer to a subfigure?

So its a fairly simple question to a problem people normally experience. I have a rough idea of what to do, but I am looking for the correct way of doing things. So in the solution I will include what would be the bare minimum requirements I think would get this problem solved. I am looking for feedback and corrections though. So please tell me, how does one go about creating subfigures within a figure. After that, caption it. Then label it for reference and then refer to it in the text?

253k 70 70 gold badges 730 730 silver badges 796 796 bronze badges asked Oct 24, 2011 at 8:05 262 2 2 silver badges 10 10 bronze badges Commented Oct 24, 2011 at 8:16 You could edit your question for including code. Commented Oct 24, 2011 at 11:55

3 Answers 3

You can use the subfig package for this. For a brief guide on how to use it, including captioning, labeling and referencing, have a look at the excellent LaTeX WikiBook section covering it.

answered Oct 24, 2011 at 8:22 Roelof Spijker Roelof Spijker 17.8k 5 5 gold badges 55 55 silver badges 63 63 bronze badges I forgot about this source. I've come right! Commented Oct 25, 2011 at 8:42

The subcaption package provides three ways to build your subfigures:

1) Using the \subcaption command inside, for example, minipage s; the syntax:

\subcaption[]> 

2) Using the subfigure environment.

3) Using the \subcaptionbox command. The syntax:

\subcaptionbox[]>[][]> 

where is the width of the resulting \parbox ; the default value is the width of the contents. specifies how the contents will be justified inside the resulting \parbox ; it can be either c (for \centering ), l (for \raggedright ), r (for \raggedleft ), or s (for no special justification). The default is c .

Here's a little example, illustrating the three approaches, and the use of \ref and \subref to cross-reference the (sub)figures:

\documentclass \usepackage \usepackage \begin \begin \begin[b] <.5\linewidth>\centering \rule% to simulate a figure \subcaption \label \end% \begin[b] <.5\linewidth>\centering \rule% to simulate a figure \subcaption \label \end \caption \label \end \begin \begin[b] <.5\linewidth>\centering \rule% to simulate a figure \subcaption \label \end% \begin[b] <.5\linewidth>\centering \rule% to simulate a figure \subcaption \label \end \caption \label \end \begin \centering \subcaptionbox>[4cm]<\rule>% \subcaptionbox>[4cm]<\rule> \caption \label \end As we can see in Figure~\ref. Subfigure~\subref of Figure~\ref shows. \end