2

The \crefrange command from the cleveref package transforms simultaneous cross-references to objects 1a, 1b and 1c as a range 1a–1c, and can be tuned further with \crefstripprefix to remove the common prefix (here, 1, yielding 1a–c).

I use subfloats references in the format 1(a), 1(b), 1(c), and using the above feature yields 1(a)–c); note the opening parenthesis before the c has been stripped because it is in common with the first label.

Is there a workaround to get 1(a)–(c)? I guess the best would be a modification of \crefstripprefix, so that it does not strip opening delimiters; my knowledge of TeX is too poor to write it myself. As a side discussion, would anyone see a drawback in making this the default behavior?

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{floatrow}
\usepackage{subcaption}

% define subfigure label 
\captionsetup[subfloat]{labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

\usepackage{cleveref}
\crefrangelabelformat{figure}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}

\begin{document}

\begin{figure}
\ffigbox[\textwidth]{
\begin{subfloatrow}[3]
\ffigbox[\FBwidth]{\includegraphics[height=2cm,width=2cm]{}}{\caption{subcap}\label{sfig:a}}
\ffigbox[\FBwidth]{\includegraphics[height=2cm,width=2cm]{}}{\caption{subcap}\label{sfig:b}}
\ffigbox[\FBwidth]{\includegraphics[height=2cm,width=2cm]{}}{\caption{subcap}\label{sfig:c}}
\end{subfloatrow}
}{\caption{cap}\label{fig:1}}
\end{figure} 
%
\begin{figure}[h]
\includegraphics[height=2cm,width=2cm]{}
\caption{cap}\label{fig:2}
\end{figure}
%
\begin{figure}[h]
\includegraphics[height=2cm,width=2cm]{}
\caption{cap}\label{fig:3}
\end{figure}

\crefrange{fig:1}{fig:3}

\crefrange{sfig:a}{sfig:c}
\end{document}
2
  • Please provide an MWE (minimum working example) that generates the issue you would like to fix. It's potentially important to know which document class you employ, which packages you load, and how the subfloats are created and \labeled.
    – Mico
    Commented Feb 20, 2018 at 15:15
  • @Mico: I added a MWE; thanks for looking into it. I use floatrow and subcaption, but I guess any subfigure mechanism creating labels like \arabic{\thefigure}(\alph{\thesubfigure}) would behave the same here. Commented Feb 20, 2018 at 15:53

1 Answer 1

0

After playing around, it seems that, at least with the floatrow/subcaption mechanism of my MWE, labels for subfigures are actually of type subfigure. This suggests to treat differently label format for figure and subfigure. However, just adding

\crefrangelabelformat{subfigure}{%
    #3#1#4--#5(\crefstripprefix{#1}{#2}#6
} % note the additional opening parenthesis after #5

is not sufficient: the labels of my subfigure references still behave like the labels of the figure references. For some reason, adding also

\crefname{subfigure}{figure}{figures}

finally makes the subfigures have a label format of their own (does this somehow “officialize” the subfigure reference type? no idea what happens).

Although this achieves what I was looking for, it still feels that patching \crefstripprefix so that it does not strip opening delimiters would be a more satisfying solution.

3
  • 'subfigure' is a separate reference type from 'figure', but it defaults to taking its format from 'figure' (even when you customise the 'figure' format). Customising the 'subfigure' format means it no longer tracks the 'figure' format. 'subequation' and 'sub[sub]section' work similarly, and maybe a few others I've forgotten. Commented Feb 24, 2018 at 10:01
  • Shouldn't need the dummy '\crefname' though - customising '\creflabelformat' should be enough. Sounds like a bug. I'll look into it. Commented Feb 24, 2018 at 10:20
  • @TobyCubitt: thank you. By the way, let me say that cleveref package is great. I wish I was good enough in TeX internal programing for a couple of customizations, like the above, or making the \crefstripprefix trick available to multiformat \cref. Commented Feb 24, 2018 at 12:25

You must log in to answer this question.

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