1

**Update

I am trying to refer to multiple subfigures in a figure caption as well as in the body of the text. The issue is that when I call \labelcref{... I am still getting the figure number in the caption when I really only want the letter. In the example below, I've highlighted what I would like to read "a-c" instead of "1a to 1c".

Here is my MWE:

\documentclass{article}

\usepackage{mwe}
\usepackage{subcaption}
\RequirePackage{xcolor} % Required for specifying custom colors
\usepackage{hyperref}
\hypersetup{pdfpagemode={UseOutlines},
    bookmarksopen=true,
    bookmarksopenlevel=0,
    hypertexnames=true, % reference roman numerals and numeric pages
    colorlinks=true,% Set to false to disable coloring links
    citecolor=blue,% The color of citations
    linktoc=all,
    linkcolor=red,% The color of references to document elements (sections, figures, etc)
    urlcolor=green,% The color of hyperlinks (URLs) 
    pdfstartview={FitV},
    unicode,
    breaklinks=true, % split up links
}
\usepackage{cleveref}
\captionsetup[sub]{labelsep=none, subrefformat=parens} % parentheses around subfigure references
%\crefrangelabelformat{subfigure}{(#3\crefstripprefix{#2}{#1}#4--#5\crefstripprefix{#1}{#2}#6)}

\begin{document}

\section{Section 1}

\begin{figure}[tbp]
    \centering
    \begin{subfigure}{.3\linewidth}
        \includegraphics[width=\linewidth]{image-a}
        \subcaption{\label{fig:1a}}
    \end{subfigure}
    \begin{subfigure}{.3\linewidth}
        \includegraphics[width=\linewidth]{image-b}
        \subcaption{\label{fig:1b}}
    \end{subfigure}
    \begin{subfigure}{.3\linewidth}
    \includegraphics[width=\linewidth]{image-c}
        \subcaption{\label{fig:1c}}
    \end{subfigure}\\[1ex]
        \begin{subfigure}{.3\linewidth}
        \includegraphics[width=\linewidth]{example-image-plain}
        \subcaption{\label{fig:1d}}
    \end{subfigure}
    \begin{subfigure}{.3\linewidth}
        \includegraphics[width=\linewidth]{example-image-golden}
        \subcaption{\label{fig:1e}}
    \end{subfigure}
    \begin{subfigure}{.3\linewidth}
        \includegraphics[width=\linewidth]{example-image-16x10}
        \subcaption{\label{fig:1f}}
    \end{subfigure}
    \caption{The top row \labelcref{fig:1a,fig:1b,fig:1c} are letters of the
    alplhabet.  \subref{fig:1a} `A'.  \subref{fig:1b} `B'.  \subref{fig:1c}
    `C'.  The bottom row \labelcref{fig:1d,fig:1e,fig:1f} are place holders.
    \subref{fig:1d} `Plain'.  \subref{fig:1d} `Golden Ratio'  \subref{fig:1f}
    `16x10'.}
    \label{fig:fig1}
\end{figure}

I can refer to \cref{fig:1a,fig:1b,fig:1c} and \cref{fig:1d,fig:1e,fig:1f}, or
even \cref{fig:1a,fig:1b,fig:1c,fig:1d,fig:1e,fig:1f}.

\end{document}

The output is as follows:

enter image description here

Is there a way to define a custom \labelcref command that I can call in a figure caption vs. in text?

\labelcref{fig:1a,fig:1b,fig:1c} to \captionlabelcref{fig:1a,fig:1b,fig:1c}?

Thanks!

5
  • Subcaption already provides \subref, which actually uses the naming convention sub@name for \label{name}. Check the aux file. May 2, 2021 at 21:03
  • Would that mean that in order to reference multiple subfigures in a figure caption, you would have to do the following?: \subref{fig:fig1a} - \subref{fig:fig1c}? I don't believe subref allows for multiple inputs like \subref{fig:fig1a,fig:fig1b,fig:fig1c}. May 2, 2021 at 21:18
  • \subref{fig:fig1a} is equivalent to \ref{sub@fig:fig1a}. Cleverref may not support \subref, but it will support its label names. May 3, 2021 at 11:39
  • Maybe I didn't ask the question very clearly but I'm trying to do the following. In my figure caption I want to refer to "subfigures a, b, c" only with the label and not the figure number i.e. (a-c). Then in the text I want to refer to Figures 1a to 1c. But I'm unable to do that. I have a figure with two rows of subfigures where the top row (a-c) are different from (d-f). I can't seem to figure out how to do that. I'll update the question to be more direct. May 3, 2021 at 16:45
  • I stand corrected. Cleverref totally ignores the contents of sub@fig:1a when creating the corresponding cref label. From the aux file: \newlabel{sub@fig:1a}{{a}{1}{\relax }{figure.caption.1}{}} \newlabel{sub@fig:1a@cref}{{[subfigure][1][1]1a}{[1][1][]1}} May 3, 2021 at 18:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.