1

After defining a newcounter (I named it "cases"), crefname, crefformat, and crefrangeformat, I incremented the counter with refstepcounter and labeled it with label. I can reference single cases with cref and multiple cases with labelcref and crefrange; however, when referencing multiple cases with cref, the type is not displayed like it is with the other methods. What am I missing?

Here's a MWE:

\documentclass{article}

\usepackage[capitalise]{cleveref}

\begin{document}

\section{My New Section}
\newcounter{cases}
\crefname{cases}{Case Study}{Case Studies}
\crefformat{cases}{Case Study~#2#1#3}
\crefrangeformat{cases}{Case Studies~#3#1#4 through~#5#2#6}

\Cref{case:a} comes first.
Next is \cref{case:b}.
Altogether, we have \cref{case:b,case:a}.  %This shows ?? instead of "Case Studies" and "and".  How do I fix this?
Trying again, we have Case Studies \labelcref{case:b,case:a}.
With a range, we have \crefrange{case:a}{case:b}.

\refstepcounter{cases} \label{case:a}
\textbf{Case Study \thecases:}
Blah.

\refstepcounter{cases} \label{case:b}
\textbf{Case Study \thecases:}
Blah.

\end{document}

Output Generated by the MWE.

An additional note: I am using a counter for these Case Studies instead of the theorem environment because the cases are relatively lengthy compared to a typical theorem and I do not want the special formatting that comes with the theorem environment.

1 Answer 1

1

\crefname and similar instructions should go before \begin{document} as should \newcounter.

\documentclass{article}

\usepackage[capitalise]{cleveref}

\newcounter{cases}
\crefname{cases}{Case Study}{Case Studies}
\crefformat{cases}{Case Study~#2#1#3}
\crefrangeformat{cases}{Case Studies~#3#1#4 through~#5#2#6}

\begin{document}

\section{My New Section}

\Cref{case:a} comes first.
Next is \cref{case:b}.
Altogether, we have \cref{case:b,case:a}.
Trying again, we have Case Studies \labelcref{case:b,case:a}.
With a range, we have \crefrange{case:a}{case:b}.

\refstepcounter{cases} \label{case:a}
\textbf{Case Study \thecases:}
Blah.

\refstepcounter{cases} \label{case:b}
\textbf{Case Study \thecases:}
Blah.

\end{document}

enter image description here

1
  • Thank you for the solution! I see this now in the cleveref documentation but wish it were more forceful in wording, like "should" instead of "can" and "expects" instead of "allows". From the Abstract (p. 1) (emphasis added): "The formatting for each cross-reference type can be fully customised in the preamble of your document." From the Introduction (p. 3) (emphasis added): "The cleveref package allows you to define the format for the different types of cross-references once-and-for-all in the preamble of your document."
    – possum
    Aug 5 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.