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}
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)
Best Answer
First of all
\subfloat
was indeed defined in very early versions of thesubcaption
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 thesubfig
package). As equivalent thesubcaption
package offers the (well documented) command\subcaptionbox
with a slightly different (and enhanced) syntax and behaviour:(Please note when using
\subcaptionbox
the\label
needs to be placed inside the caption argument, not inside the content argument.)