I am using the cleveref package and I am very happy with it. However, I encountered one problem I wasn't able to solve. I am probably
just not combining the syntax correctly. This is highly connected
to the question already asked, here: Crossreference in Ref Range [(1a-1e) to (1a-e)] I am sorry if this is already answered.
The above thread explains how to reference ranges of subequations (or floats) like 1a to e, rather than the default 1a to 1e. I would like to have the same feature for a pair of references combined by an "and", namely: 1a and b rather than the default 1a and 1b.
Here is a MWE:
\documentclass{book}
\usepackage{cleveref}
\usepackage{subfig}
\crefrangelabelformat{figure}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}
\crefmultiformat{figure}{figs.~#2#1#3}{ and~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\begin{document}
\begin{figure}
\centering
\subfloat[][]{\rule{2.cm}{2.cm}\label{subfig:1a}}
\subfloat[][]{\rule{2.cm}{2.cm}\label{subfig:1b}}\\
\subfloat[][]{\rule{2.cm}{2.cm}\label{subfig:1c}}
\subfloat[][]{\rule{2.cm}{2.cm}\label{subfig:1d}}\\
\caption{\label{fig:1}my figures}
\end{figure}
Referencing a range works as wanted and gives figs. 1a-b: \cref{subfig:1a,subfig:1b,subfig:1c,subfig:1d}.\\
But, referencing a pair gives \cref{subfig:1a,subfig:1b}, rather than the desired figs. 1a and b.\\
\end{document}
I think combining \crefstripprefix together with \crefmultiformat{figure} (which I use in the MWE to remove the "()") could give me the desired result. But I am not able to get the correct syntax to make this work, since I am pretty unfamiliar with the deep-down latex syntax.


\edefinstead of\xdef. The latter is needed to make a global assignment. – Andrew Swann Jan 20 '23 at 07:35abcecase, the first part gets past to the range constructor, so this also needs to define the\mycreffirstargmacro. Code updated. – Andrew Swann Jan 20 '23 at 16:40