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 reference a subfigure like so:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
     \subfloat[A subcaption.]{\label{figure:subfigure1}\includegraphics[width=2cm]{logo}}
     \caption{A caption.}
     \label{figure:figure1}
\end{figure}

\noindent
Subfigure \ref{figure:subfigure1}, Figure \ref{figure:figure1}.

\end{document}

However, I am getting a "Reference undefined" warning and the output is:

enter image description here

When I am using

\usepackage{subfig} 

instead of

\usepackage{caption}
\usepackage{subcaption}

the output is as expected (references are all found).

What am I doing wrong?

Update

I checked the package versions. Indeed, they are old:

Package: subcaption 2008/08/31 v1.0b 
Package: caption 2009/10/09 v3.1k caption kernel (AR)
share|improve this question
    
Welcome to TeX.SE! Your first MWE doesn't compile for me; \subfloat is not from the subcaption package. Instead, use \begin{subfigure}{<width>}<Figure code>\caption{<caption>}\label{<label>}\end{subfigure} and all will be good :) –  cmhughes Jan 2 '13 at 18:53
    
silly question, why not use subfig then if it works? I don't know subcaption, so the syntax may be correct, but by the look of it the syntax you are using is that of subfig. –  ArTourter Jan 2 '13 at 18:53
    
@cmhughes Thank you! Yes this would work, however I am using subfloats for a reason (to span a figure over multiple pages using continuedfloat). –  Tobold Jan 2 '13 at 18:57
    
@ArTourter Cannot use subfig since it doesn't play nicely with hyperref. –  Tobold Jan 2 '13 at 18:57
    
@ArTourter Yes, might be wrong about that, I don't have a MWE. In the example above, hyperref works properly. Still it doesn't in my main document. A major benefit of using subcaption is IMHO that I can use both subfigure and subfloat. It would therefore be nice to solve the issue at hand. –  Tobold Jan 2 '13 at 19:09

1 Answer 1

up vote 2 down vote accepted

First of all \subfloat was indeed defined in very early versions of the subcaption package but this was never a documented feature (and has proven to be a very bad idea anyway since it was not 100% compatible with \subfloat offered by the subfig package). As equivalent the subcaption package offers the (well documented) command \subcaptionbox with a slightly different (and enhanced) syntax and behaviour:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
     \subcaptionbox{A subcaption.\label{figure:subfigure1}}{\includegraphics[width=2cm]{logo}}
     \caption{A caption.}
     \label{figure:figure1}
\end{figure}

\noindent
Subfigure \ref{figure:subfigure1}, Figure \ref{figure:figure1}.

\end{document}

(Please note when using \subcaptionbox the \label needs to be placed inside the caption argument, not inside the content argument.)

share|improve this answer
    
This seems to work. Didn't know about \subcaptionbox, thank you! –  Tobold Jan 2 '13 at 19:43
    
BTW: \subcaptionbox has some additional optional parameters, better take a (short) look at the subcaption package documentation. –  Axel Sommerfeldt Jan 2 '13 at 20:03

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.