# Referencing subfigures in main caption (with \subfloat and \subref)

I've used subfloat to include subfigures, with their relevant labels but with empty captions. what I'm going to do is to reference these figures with \subref in the main caption of the figure. But what I get is only ?? signs in the caption [main caption]. I can't figure out what's the problem. this is what I have:

\begin{figure}
\centering
\subfloat[][]
{
\includegraphics[scale=0.55]{signal}
\label{signal_model}
}
\subfloat[][]
{
\includegraphics[scale=0.55]{amplitude}
\label{amplitude_mod}
}
\caption{phase noise variability: \subref{signal model} some text \subref{amplitude_mod} some other text}
\end{figure}

• You need a subcaption nevertheless, even if empty, so that the subfigure is at least labelled. – JLDiaz Jul 8 '12 at 16:53
• can you turn your snippet into a complete MWE? – cmhughes Jul 8 '12 at 17:13
• Actually I want to have labeled subfigures, i.e. to have (a) (b) (c) etc. below each subfigure without sub-captions. but I want to cite or refer them in the main caption of the figure (I thought it's possible with '\subref') – pasha Jul 8 '12 at 17:24
• I got the answer, but I think something missing with subcaption package: "The subcaption package was updated to version 1.1. It got a new option for selecting a format used by \subref, and a new command called \phantomsubcaption for referencing a sub-figure without caption. Furthermore the subcaption package documentation was enhanced regarding references." – pasha Jul 8 '12 at 17:49
• If you are really using the subcaption package (and not the subfig one) please use \subcaptionbox instead of \subfloat and put the \label inside the caption text, not inside the sub-figure body. – Axel Sommerfeldt Jul 9 '12 at 6:45

You need to \protect the \subref command in the caption:

\caption{Phase noise variability: \protect\subref{signal_model} some text
\protect\subref{amplitude_mod} some other text}


MWE:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}

\begin{figure}
\centering

\subfloat[][]{\includegraphics[scale=0.55]{example-image-a}\label{signal_model}}
\subfloat[][]{\includegraphics[scale=0.55]{example-image-b}\label{amplitude_mod}}

\caption{Phase noise variability: \protect\subref{signal_model} some text
\protect\subref{amplitude_mod} some other text}

\end{figure}
\end{document}


• +1 and BIG thanks for this .. I was struggling with this (my documentclass prohibits use of caption, and therefore subcaption, where for some reason \subref does not need \protect) – user1207217 Mar 14 '13 at 16:53
• Thanks for this answer. I just wanted to add the reason for using \protect: The command \subref{} is a fragile command, and \caption has a moving argument. The \protect command is needed whenever we use a fragile command in a moving argument. – hadi May 27 '14 at 21:47
• @hadi That doesn't really do much to explain the need to \protext that \subref call. It works perfectly fine in the subfigure package, so at a first look it is a regression in behaviour. Why is making \subreffragile an advantage in any way, other than breaking code which used to work? – E.P. Aug 31 '16 at 13:20