# Referencing Subfigure in Subfloat

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:

When I am using

\usepackage{subfig}


\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)

-
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

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.)

-
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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9081020951271057, "perplexity": 5725.339200540493}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-10/segments/1394678694619/warc/CC-MAIN-20140313024454-00072-ip-10-183-142-35.ec2.internal.warc.gz"}