44

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}
7
  • 1
    You need a subcaption nevertheless, even if empty, so that the subfigure is at least labelled.
    – JLDiaz
    Jul 8, 2012 at 16:53
  • 1
    can you turn your snippet into a complete MWE?
    – cmhughes
    Jul 8, 2012 at 17:13
  • 1
    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, 2012 at 17:24
  • 1
    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.
    – user2574
    Jul 9, 2012 at 6:45
  • 1
    Turns out refcheck can also mess with \subref. Was getting ??sub@<ref> instead of (a), and it showed properly as (a) when I turned off refcheck. Note that \protect\subref while refcheck was on didn't fix it.
    – Sterling
    Mar 15, 2022 at 7:04

1 Answer 1

57

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}

enter image description here

9
  • 3
    +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) Mar 14, 2013 at 16:53
  • 15
    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, 2014 at 21:47
  • 3
    @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, 2016 at 13:20
  • 1
    @hadi - thanks! Now a newbie like me still needs to read this and then have a look at this (harder still). Mar 21, 2020 at 4:10
  • 1
    Thanks, can someone explain what protect does?
    – Hao S
    Sep 24, 2021 at 1:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .