Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a figure with subfigures, and then reference them from the caption of the main figure:

\begin{figure}
    \begin{subfigure}
        A figure
        \caption{}
        \label{a}
    \end{subfigure}
    ~
    \begin{subfigure}
        B figure
        \caption{}
        \label{b}
    \end{subfigure}
    \caption{ \ref{a}) about figure A, \ref{b}) about figure B }
\end{figure}

This doesn't work as written, how do I do something similar?

share|improve this question
1  
The environment subfigure is provided by the package subfigure which is obsolete. You should use subcation instead. However if I use your code snippet it works well. –  Marco Daniel Apr 7 '13 at 19:40
1  
Marco meant subcaption. –  Jubobs Apr 7 '13 at 19:42
    
weirdly enough, I'm using the package subcaption... which also provides the subfigure environment –  Andrew Spott Apr 7 '13 at 19:48
    
@AndrewSpott: The environment subfigure of subcaption has an mandatory argument. –  Marco Daniel Apr 7 '13 at 19:51
2  
@AndrewSpott such misunderstandings would not occur if your question contained a complete document, which is why we always ask for examples to start with \documentclass and end with \end{document} showing all packages used. –  David Carlisle Apr 7 '13 at 19:53

1 Answer 1

up vote 5 down vote accepted

The package subfigure provides the environment subfigure. I guess you are using it. This package is obsolete and you should use the package subfig or subcaption (recommended) (provides nearly the same environment).

However the following example works well:

\documentclass{article}
\usepackage{subfigure}
\usepackage{caption}
\begin{document}
\begin{figure}
    \begin{subfigure}
        A figure
        \caption{}
        \label{a}
    \end{subfigure}
    ~
    \begin{subfigure}
        B figure
        \caption{}
        \label{b}
    \end{subfigure}
    \caption{ \ref{a}) about figure A, \ref{b}) about figure B }
    \label{fig:TheWholeFigure}
\end{figure}

\end{document}

Using subcaption:

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
    \begin{subfigure}{.49\linewidth}
        A figure
        \caption{}
        \label{a}
    \end{subfigure}
    \hfill
    \begin{subfigure}{.49\linewidth}
        B figure
        \caption{}
        \label{b}
    \end{subfigure}
    \caption{ \ref{a}) about figure A, \ref{b}) about figure B }
    \label{fig:TheWholeFigure}
\end{figure}

\end{document}

enter image description here

If you want to reference the whole image, use \ref{fig:TheWholeFigure}.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.