2

My question is a more general (and hopefully clearer) formulation of this one.

With package cleveref, when referencing simultaneously several labeled objects, one can either use the multiformat command \cref, yielding for instance refs 1, 2 and 3, or the range format command \crefrange, yielding refs 1–3.

If the labeled objects are 1a, 1b, 1c, the range format can be tuned with \crefstripprefix to remove the common prefix;

\crefrangelabelformat{<type>}{#3#1#4--#5\crefstripprefix{#1}{#2}#6}

yielding refs 1a–c instead of refs 1a–1c.

I would like to achieve something similar with the multiformat, that is refs 1a, b, and c. Unfortunately, in contrast to the above where #1 stands for the first label of the range and #2 stands for the last label, the \creflabelformat command configures labels individually (only placeholder #1 available, the #2 and #3 tunes the hyperlink, juste like #3 to #6 above).

The output of \cref with a series of label is tuned by the \crefmultiformat command, where a placeholder #1 appearing in its arguments stands for each label of the series, one at a time. Is there a way to make each label first undergo a transformation, tuned by a command “\crefmultilabelformat” with two placeholders, where #1 would stand for, say the first rendered label of the series, and #2 would stand for each of the others?

\documentclass{article}
\usepackage{floatrow}
\usepackage{subcaption}

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

\begin{document}
\begin{figure}
\ffigbox[\textwidth]{
\begin{subfloatrow}[3]
\ffigbox[\FBwidth]{\quad a \quad}{\caption{a}\label{sfig:a}}
\ffigbox[\FBwidth]{\quad b \quad}{\caption{b}\label{sfig:b}}
\ffigbox[\FBwidth]{\quad c \quad}{\caption{c}\label{sfig:c}}
\ffigbox[\FBwidth]{\quad d \quad}{\caption{d}\label{sfig:d}}
\end{subfloatrow}
}{\caption{cap}\label{fig:1}}
\end{figure} 
%

\crefrange{sfig:a}{sfig:c} % renders 1a-c, juste like I want

\cref{sfig:a,sfig:b,sfig:d} % renders 1a, 1b and 1d, and I would like 1a, b, and d.
\end{document}
2
  • I don't really see the problem. Is it that the stripping command doesn't work in a definition of the multi-format?
    – cfr
    Commented Feb 21, 2018 at 1:14
  • @cfr: if you try to create automatically the cross-reference "refs 1a, b, and c" (or "figs. 1a, b, and d" in the MWE), you will see the problem: the labels in the multiformat cannot be defined in function of the other labels. It is not the the stripping command does not work, but rather that it cannot be used. Commented Feb 21, 2018 at 10:24

1 Answer 1

1

This doesn't need a new command, it can be done with the existing \crefmultiformat by using a macro to pass the prefix information from the first component to the others, like so:

\documentclass{article}
\usepackage{floatrow}
\usepackage{subcaption}

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

\crefmultiformat{figure}%
  {\edef\mycrefprefixinfo{#1}figs.~#2#1#3}%
  { and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}%
  {, #2\crefstripprefix{\mycrefprefixinfo}{#1}#3}%
  {, and~#2\crefstripprefix{\mycrefprefixinfo}{#1}#3}

\begin{document}
\begin{figure}
\ffigbox[\textwidth]{
\begin{subfloatrow}[3]
\ffigbox[\FBwidth]{\quad a \quad}{\caption{a}\label{sfig:a}}
\ffigbox[\FBwidth]{\quad b \quad}{\caption{b}\label{sfig:b}}
\ffigbox[\FBwidth]{\quad c \quad}{\caption{c}\label{sfig:c}}
\ffigbox[\FBwidth]{\quad d \quad}{\caption{d}\label{sfig:d}}
\end{subfloatrow}
}{\caption{cap}\label{fig:1}}
\end{figure}

\crefrange{sfig:a}{sfig:c} % renders "1a-c", just like I want.

\cref{sfig:a,sfig:b,sfig:d} % renders "1a, b, and d", just like you want.
\end{document}
2
  • That is perfect. You might consider putting it in the documentation. Cheers for your great package! Commented Mar 4, 2018 at 21:43
  • Thank you, however if I add another subcaption in the figure \ffigbox[\FBwidth]{\quad e \quad}{\caption{e}\label{sfig:e}} and call \cref{sfig:a,sfig:b,sfig:c,sfig:e} it fails. Any ideas?
    – Chachni
    Commented Jan 19, 2023 at 22:50

You must log in to answer this question.

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