I'm using the subfig package to handle subfigures and I'm getting a really puzzling error, where referencing with \ref{} to a subfigure assigns it the wrong figure number, even though the reference to the global figure does work:
A MWE example is the following:
\documentclass{report}
\usepackage{subfig}
\usepackage{caption}
\usepackage{lmodern}
\usepackage{bm}
\begin{document}
\chapter{Title}
\captionsetup[figure]{position=top}
\begin{figure}[!htbp]
\centering
\begin{tabular}{cc}
\subfloat[caption 1a]{
\label{fig1a}
\rule{3cm}{2cm}
}
&
\subfloat[caption 1b]{
\label{fig1b}
\rule{3cm}{2cm}
}
\end{tabular}
\caption{Sample caption.}
\label{fig1}
\end{figure}
\begin{figure}[hbt]
\centering
\subfloat{
\rule{3cm}{2cm}
\label{fig2a}
}
\hspace{5mm}
\subfloat{
\rule{3cm}{2cm}
\label{fig2b}
}
\caption{
Referencing inside the caption.
\texttt{\textbackslash subref\{fig2a\}}: \protect\subref{fig2a},
\texttt{\textbackslash subref\{fig2b\}}: \protect\subref{fig2b},
\texttt{\textbackslash subref*\{fig2a\}}: \protect\subref*{fig2a},
\texttt{\textbackslash subref*\{fig2b\}}: \protect\subref*{fig2b},
\texttt{\textbackslash ref\{fig2a\}}: \protect\ref{fig2a},
\texttt{\textbackslash ref\{fig2b\}}: \protect\ref{fig2b},
\texttt{\textbackslash ref\{fig2\}}: \protect\ref{fig2}.
}
\label{fig2}
\end{figure}
Subref works correctly:
\texttt{\textbackslash subref\{fig2a\}}:~\protect\subref{fig2a},
\texttt{\textbackslash subref\{fig2b\}}:~\protect\subref{fig2b},
\texttt{\textbackslash subref*\{fig2a\}}:~\protect\subref*{fig2a},
\texttt{\textbackslash subref*\{fig2b\}}:~\protect\subref*{fig2b}.
$\quad$
Figure ref works correctly:
\texttt{\textbackslash ref\{fig2\}}:~\protect\ref{fig2}.
$\quad$
Direct ref to subfigures doesn't:
\texttt{\textbackslash ref\{fig2a\}}: \protect\ref{fig2a},
\texttt{\textbackslash ref\{fig2b\}}: \protect\ref{fig2b},
\end{document}
What causes this, and how can I fix it?


\captionsetup[figure]{position=top}and place the figure caption below the figure content. This way you are cheatingsubfigandsubfigdoes not like it, As documented in section "The Caption Position Option" of thesubfigdocumentation. – Sep 11 '16 at 17:09\captionsetup[figure]{position=bottom}\captionsetup[subfigure]{position=top}should do the trick. – Sep 12 '16 at 08:07