2

How do I get subfig-like captions for a single figure? I've got images that have multiple panels each, and I'd like to make a caption for all the sub-panels, as well as be able to reference each sub-panel. Something like Fig 1A, 1B etc.

Update This is what I've come up with, based on Werner's answer:

\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{letterpaper}

\usepackage{graphicx}

\usepackage[labelformat=simple]{caption,subcaption}
\usepackage{hyperref}
\usepackage{varioref}

\renewcommand\thesubfigure{\Alph{subfigure}}

\begin{document}

Tofu gluten-free VHS locavore, viral williamsburg +1 cliche fanny pack leggings terry richardson cred photo booth artisan. Echo park locavore jean shorts shoreditch before they sold out, farm-to-table keytar high life banksy tofu sartorial marfa. Gentrify butcher leggings 

\captionsetup{singlelinecheck=false}

\begin{figure}[htb]
    \includegraphics[scale=1]{figure2}
    \caption{This is a general heading for figure 1.}\label{fig:1}

    \subcaptionbox{This is something about figure 1A.}[\linewidth]{\label{fig:1a}}
    \subcaptionbox{This is more more more more more more more more more more text about figure 1B. Sustainable terry richardson craft beer homo, cardigan wayfarers blog commodo DIY quinoa sartorial american apparel nostrud.\label{fig:1b}}[\linewidth]  {}


\end{figure}

Here's a ref to fig \vref{fig:1b}.Skateboard tempor hoodie helvetica quis. Sustainable terry richardson craft beer homo, cardigan wayfarers blog commodo DIY quinoa sartorial american apparel nostrud. Williamsburg aute mcsweeney's wes anderson. Dolor eiusmod tempor assumenda stumptown, delectus irony laboris 


\end{document}  

1 Answer 1

2

This example, slightly altered from the subcaption package documentation is probably what you're looking for (\rule is meant for illustration only):

\documentclass{article}
\usepackage{caption,subcaption}
\begin{document}
\begin{figure}
  \hfill\subcaptionbox{A subfigure\label{fig:1a}}[8em]{\centering \rule{5pt}{3em}}
  \hfill\subcaptionbox{Another subfigure\label{fig:1b}}{\centering \rule{10em}{2em}}
  \hfill\subcaptionbox{A final subfigure\label{fig:1c}}[9em]{\centering \rule{2em}{4em}}
  \hfill\null
  \caption{A figure}\label{fig:1}
\end{figure}
Look at Figure~\ref{fig:1a} and~\ref{fig:1b}, or even Figure~\ref{fig:1c}. Everything is contained in Figure~\ref{fig:1}.
\end{document}

Subfigures in a figure

The subcaption package necessarily requires its contents to be typeset in a box. As such, the use of the \subcaptionbox{<heading>}[<width>][<inner-pos>]{<contents>} is ideal to have possible variable-width (the <width> argument is optional) contents with a subcaption. Without the <width> specification, the subfigure will be put in a box of "natural width" equivalent to the width of <contents>. So, if you have images that are very wide, you don't have to worry about specifying <width>. However, for a very narrow <contents> specifying <width> will allow for correct typesetting of the caption.

Also, there are ways to manipulate the representation of the your (sub-)captions and references.

5
  • this seems to work, though what does it mean when it says "Please note that the \subcaption command must be applied inside its own box or environment"?
    – Noah
    Commented Aug 16, 2011 at 18:55
  • This was done by design, and hence the typesetting of \subcaption inside a minipage. Alternatively, you could use the \subcationbox{<heading>}[<width>][<inner-pos>]{<contents>} and insert \label{...} inside <heading>.
    – Werner
    Commented Aug 16, 2011 at 19:02
  • @Noah: In terms of compatibility in your code (and ultimately longevity), here's something to consider: subcaption vs. subfig. That's why I leaned towards subcaption, which then forces you to use boxes. What is wrong with the boxes? Also do you have subfigures that span \textwidth, or do you just want your caption to span \textwidth?
    – Werner
    Commented Aug 16, 2011 at 20:04
  • okay, I've modified my code to use minipage/subcaptions. I just want the captions to span \textwidth, as the figures themselves are likely to be wider or narrower than that. Is the \hspace a good solution or would you do something differently?
    – Noah
    Commented Aug 16, 2011 at 20:21
  • 1
    @Noah: If you want captions to span the entire width, then use \linewidth rather than \textwidth. I've updated my answer with some description of this. The subcaption package allows to fix your subfigure with. If this is what you want, then use \subcaptionbox{<heading>}[\linewidth]{<contents>}.
    – Werner
    Commented Aug 16, 2011 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .