[Tex/LaTex] Subfigure labelling for a single figure

floatssubfloats

I have a single figure containing two plots. The two plots are already labelled within the figure using (a), (b).

My single figure

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.

Best Answer

subcaption package offers a convenient \phantomcaption command to suppress the label generation on the subfloats.

\documentclass{article}
\usepackage{subcaption}
\usepackage{cleveref}
\usepackage{mwe} %<- For dummy images

\begin{document}

\begin{figure}
    \centering
    \begin{subfigure}[t]{0.47\textwidth} % contains the two plots in a single figure
        \includegraphics[width=\textwidth]{example-image-a}
        \phantomcaption
        \label{fig:imga}
    \end{subfigure}
    \begin{subfigure}[t]{0\textwidth} % the hidden unwanted image
         \includegraphics[width=\textwidth]{example-image-b}
         \phantomcaption
         \label{fig:imgb}   
    \end{subfigure}
\caption{Main caption here}
\label{fig:main}
\end{figure}

We can use \Cref{fig:imga} but we won't use \Cref{fig:imgb}

\end{document}

Then the result is as desired.

enter image description here

Related Question