I have a single figure containing two plots. The two plots are already labelled within the figure using (a), (b).
So far I have been referencing the figures using the cleveref
package as
\cref{fig:img1}(a)
However the (a)
is not part of the reference link.
My attempt at a work around is to use the subfigure
environment
\documentclass{article}
%\usepackage{jheppub}
\usepackage{subcaption}
\usepackage{cleveref}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.47\textwidth} % contains the two plots in a single figure
\includegraphics[width=\textwidth]{./img.pdf}
\caption{}
\label{fig:imga}
\end{subfigure}
\begin{subfigure}[t]{0\textwidth} % the hidden unwanted image
\includegraphics[width=\textwidth]{./img.pdf}
\caption{}
\label{fig:imgb}
\end{subfigure}
\caption{Main caption here}
\label{fig:main}
\end{figure}
\end{document}
So now when I reference \cref{fig:imga}
it returns figure 1a etc. The only problem other than the spacing between the figure and the caption is that I have the figure label (a)
under the first figure and a floating (b)
under the second unwanted image.
Using \caption*{}
results in the labels not being counted, so the references just return the section number.
Ideally I would like to hide these labels, but not disable them as I want to use them in the references.
EDIT.
Using \phantomcaption
in place of the two subfigure \caption{}
's has worked perfectly.
\phantomcaption
command for the empty caption.\phantomcaption
command. I have used it for both as neither label was wanted. Thank you.(a)
and(b)
labels in the plots, which are very easy to overlook. Assign "real" captions to each subfigure instead.) hat way, you'll gain a lot of flexibility, and assigning labels to the entire figure as well as to each subfigure (and creating cross-references to each entity) becomes almost trivially simple.