# How can I get multiple sub-references to appear as a range in the caption?

I have 2 plots which in turn have 4 plots each, which I label as shown in the MWE. I am trying to get the caption of the figure to read:

Figure 1: (a)-(d) XYZ and (e)-(h) PQR

In the MWE I am doing it manually. How do I provide sub-references for all the figures such that I get the caption shown above? I cannot get \subref{fig_top_1,fig_top_2,fig_top_3,fig_top_4} to generate the desired. How can I get multiple sub-references to appear as a range in the caption (as above)?

MWE

\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx,float}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}
\usepackage{cleveref}

\begin{document}
\begin{figure}[H]
\centering
\subfloat{\label{fig_top_1}}
\subfloat{\label{fig_top_2}}
\subfloat{\label{fig_top_3}}
\subfloat{\label{fig_top_4}}
\includegraphics[width=70mm]{example-image-a}
\subfloat{\label{fig_bottom_1}}
\subfloat{\label{fig_bottom_2}}
\subfloat{\label{fig_bottom_3}}
\subfloat{\label{fig_bottom_4}}
\includegraphics[width=70mm]{example-image-b}

\caption{\protect\subref{fig_top_1,fig_top_2,fig_top_3,fig_top_4} XYZ
and \protect\subref{fig_bottom_1}--\subref{fig_bottom_4} PQR}
\label{fig_top_bottom}
\end{figure}

\end{document}


The following solution lets you use both \cref and \crefrange to create the cross-references. Note that \subref is not used.

\documentclass{article}

\usepackage{graphicx}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}
\makeatletter
\renewcommand\p@subfigure{} % no figure-number prefixes in cross-refs to subfigures
\makeatother

\usepackage{cleveref}
\crefformat{subfigure}{(#2#1#3)}
\crefrangeformat{subfigure}{(#3#1#4)--(#5#2#6)}

\begin{document}
\begin{figure}
\centering
\subfloat{\label{fig_top_1}}\subfloat{\label{fig_top_2}}
\subfloat{\label{fig_top_3}}\subfloat{\label{fig_top_4}}
\includegraphics[width=70mm,height=30mm]{example-image-a}

\subfloat{\label{fig_bot_1}}\subfloat{\label{fig_bot_2}}
\subfloat{\label{fig_bot_3}}\subfloat{\label{fig_bot_4}}
\includegraphics[width=70mm,height=30mm]{example-image-b}

\caption{\cref{fig_top_1,fig_top_2,fig_top_3,fig_top_4} XYZ and
\crefrange{fig_bot_1}{fig_bot_4} PQR}
\label{fig_top_bot}
\end{figure}

\end{document}

• This works fine. But it causes the subfigure references elsewhere to be without figure prefix. Is there a way to prevent this? Should I ask a separate question? Feb 5, 2018 at 7:24
• @nxkryptor - Yes, please post a new query. Do make sure to state what exactly isn't working as you would expect.
– Mico
Feb 5, 2018 at 7:27