Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.