I was going through some crazy hoops to get minipage and subfloat work nicely (?) together, only to find out in the very end that I screwed up the figure references.
I have a figure with two subfloats, one on the left one on the right. The left is composed of two graphics above one another. That last fact causes big trouble because I cannot use \\
or \newline
in subfloat
alone. So I build a minipage
around it, but then the subfloat
cannot contain the minipage
, so I reversed their nesting:
\documentclass[a4paper]{book}
% note: the following packages are _givens_, I cannot change them at this point
\usepackage[top=35mm, bottom=38mm, inner=40mm, outer=24mm]{geometry}
\usepackage[hang,small]{caption}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
As shown in Fig.~\ref{fig:right}...
\begin{figure}
\centering
\begin{minipage}{0.39\textwidth}%
\includegraphics[width=1\textwidth, trim=0 0 0 -70mm]{figures/zelle148_IMG_1903m.jpg}\\[2mm]%
\includegraphics[width=1\textwidth, trim=0 -60mm 0 0]{figures/zelle148_IMG_1901m.jpg}%
\\\centering \subfloat[Left]{\hspace{0.9\textwidth}}\label{fig:left}
\end{minipage}%
\begin{minipage}{0.58\textwidth}%
\includegraphics[width=1\textwidth, trim=-2mm 0 0 0]{figures/Zelle148ScoreCut.pdf}%
\\\centering \subfloat[Right]{\hspace{1\textwidth}}\label{fig:right}
\end{minipage}%
\caption{Full caption}
\label{fig:both}
\end{figure}
\end{document}
The problem is, I get errors
Package caption Warning: \label before \caption on input line 20.
LaTeX Warning: Reference `fig:right' on page 1 undefined on input line 9.
LaTeX Warning: There were undefined references.
The figure result looks as I want:
But the reference in the text just shows up as "??" instead of "1b".
subfig
withsubcaption
which I read is recommended. I didn't disturb the rest of the thesis I have formatted so far, so I'm ok to make this change if it helps.