# Overriding cleveref in image captions to reflect \protect\subref

I am using cleveref throughout my document for cross referencing. There are only certain instances where I need to referencing to be partial ( (a) instead of Fig 1a). Usually I encounter this in the main figure caption for referencing a sibfigure (as present in MWE).

In other words, I would like to use the 'cleveref multiple reference arguments' option, so that I can get (a) to (d), instead of 1(a) to 1(d).

I Implemented solutions in Combining cleveref and subref ,but they are not working for \cref{ref1,ref2,ref3} format

MWE

\documentclass{article}

\usepackage{graphicx}
\usepackage{subfig}
\usepackage{caption}
\usepackage{cleveref}

\begin{document}
\begin{figure} []
\centering
\subfloat[][first figure]{\includegraphics[width= 0.485\textwidth]{example-image-a} \label{CHP:fig:EC:1}}
\subfloat[][first figure]{\includegraphics[width= 0.485\textwidth]{example-image-b}\label{CHP:fig:EC:2}}

\subfloat[][first figure]{\includegraphics[width= 0.485\textwidth]{example-image-c}\label{CHP:fig:EC:3}}
\subfloat[][first figure]{\includegraphics[width= 0.485\textwidth]{example-image-a} \label{CHP:fig:EC:4}}

\caption{Need to override \cref{CHP:fig:EC:1,CHP:fig:EC:2,CHP:fig:EC:3,CHP:fig:EC:4}
to look like \protect\subref{CHP:fig:EC:1} to \protect\subref{CHP:fig:EC:4}
just for the main figure captions}
\label{CHP4:fig:EC}
\end{figure}
\end{document}

• I'm afraid your objective isn't entirely clear. Please edit your posting to state in a couple of sentences what exactly it is you're trying to achieve. Thanks. – Mico Sep 17 '17 at 21:06
• You could just use \protect\subref{CHP:fig:EC:1} to \protect\subref{CHP:fig:EC:4} instead of \cref{CHP:fig:EC:1,CHP:fig:EC:2,CHP:fig:EC:3,CHP:fig:EC:4}. You could create an own macro that works that way: \newcommand{\refsubrange}[2]{\protect\subref{#1} to \protect\subref{#2}} – Skillmon Sep 17 '17 at 21:19
• Thats what I am doing in the MWE.....just wanted my cross-referencing to be consistent throughout the document. – Fowaz Ikram Sep 17 '17 at 21:24
• @FowazIkram and that's why I said you could use that code. No need to redefine some stuff if you already know how the output should look like. Define a new command and you're done. Locally redefining \cref just so you can always type \cref doesn't seem right. – Skillmon Sep 17 '17 at 21:47

Since you're using the caption package, you should probably also use the subcaption package, not the subfig package.

I think an easy solution consists of (a) issuing the instructions

\makeatletter
\renewcommand\p@subfigure{}
\makeatother


immediately after \begin{figure} and (b) using \labelcref instead of \cref to generate the cross-referencing call-outs. No need to \protect the \labelcref directive, by the way.

\documentclass{article}
\usepackage{graphicx,subcaption}
\usepackage{cleveref}
\crefname{subfigure}{subfig.}{subfigs.}

\begin{document}
\begin{figure}
\makeatletter
\renewcommand\p@subfigure{}
\makeatother
\begin{subfigure}{0.485\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{first figure}  \label{CHP:fig:EC:1}
\end{subfigure}\hfill
\begin{subfigure}{0.485\textwidth}
\includegraphics[width=\textwidth]{example-image-b}
\caption{second figure} \label{CHP:fig:EC:2}
\end{subfigure}

\medskip
\begin{subfigure}{0.485\textwidth}
\includegraphics[width=\textwidth]{example-image-c}
\caption{third figure}  \label{CHP:fig:EC:3}
\end{subfigure}\hfill
\begin{subfigure}{0.485\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{fourth figure} \label{CHP:fig:EC:4}
\end{subfigure}

\caption{Cross-references to \labelcref{CHP:fig:EC:1,CHP:fig:EC:2,CHP:fig:EC:3,CHP:fig:EC:4}}
\label{CHP4:fig:EC}
\end{figure}

\noindent
As illustrated by \cref{CHP:fig:EC:1,CHP:fig:EC:2,CHP:fig:EC:3,CHP:fig:EC:4} of \cref{CHP4:fig:EC}, \dots
\end{document}


Addendum: If you need the cross-referenced subfigures to be labeled as (a), (b), etc. rather than as a, b, etc., please issue the following directives in the preamble (after loading subcaption):

\captionsetup[subfigure]{labelformat=simple}
\renewcommand{\thesubfigure}{(\alph{subfigure})}

• Thanks for the suggestion. I will surely keep that on my record I had a long and hard history with the subfigure environment, I finally resorted to subfloats to resolve it :) – Fowaz Ikram Sep 18 '17 at 1:45