When using subfloats over multiple pages I have used \ContinuedFloat
to carry on the figure environment which also preserves the numbering. However, when I try to reference the whole figure, cleveref
does not get the label correct.
There are numerous answers available for misnumbering but not mislabeling.
Have I put the \label
in the wrong place?
MWE as follows with all the packages I'm using:
\documentclass[12pt,demo]{elsarticle}
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tabu}
\usepackage{multirow}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage[capitalise]{cleveref}
\usepackage{booktabs}
\usepackage{comment}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{subfig}
\usepackage{caption}
\begin{document}
\section{Section Title}
\Cref{fig:First} and \cref{fig:Second} can be seen in \cref{fig:Both}.
\begin{figure}
\centering
\subfloat[Caption for the first image]{
\includegraphics[width=.4\columnwidth]{Img1}%
\label{fig:First}%
}
\phantomcaption
\end{figure}
\begin{figure}
\ContinuedFloat
\centering
\subfloat[Caption for the second image]{
\includegraphics[width=.4\columnwidth]{Img2}%
\label{fig:Second}%
}
\caption{Main Caption}%
\label{fig:Both}%
\end{figure}
\end{document}
Best Answer
I can offer a solution that uses the subcaption package and its
subfigure
environment instead of thesubfig
package and its\subfloat
macro. I suggest making this change because the\ContinuedFloat
macro (which is provided by thecaption
package, which is loaded automatically by thesubcaption
package) seems to interact in an unfortunate way with thesubfig
package's macros, ending up confusingcleveref
. Possibly because thesubcaption
andcaption
packages were created by the same author, labeling does not get messed up if you employ\ContinuedFloat
along withsubfigure
environments.The syntax for creating subfigures needs to be adjusted a bit if you use the macros of the
subcaption
package. However, I trust the adjustments won't be too burdensome.