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)
\subfloat
is not from thesubcaption
package. Instead, use\begin{subfigure}{<width>}<Figure code>\caption{<caption>}\label{<label>}\end{subfigure}
and all will be good :)subfig
then if it works? I don't knowsubcaption
, so the syntax may be correct, but by the look of it the syntax you are using is that ofsubfig
.hyperref
works properly. Still it doesn't in my main document. A major benefit of usingsubcaption
is IMHO that I can use bothsubfigure
andsubfloat
. It would therefore be nice to solve the issue at hand.