Let's say I have this:
\documentclass{article}
\usepackage{cleveref}
\begin{document}
\section{Section One}
\label{a:sec1}
\cref{a:sec1}
\section{Section Two}
\label{b:sec2}
\cref{b:sec2}
\end{document}
Cleveref will now reference "Section 1" and "Section 2" because the label comes after a section. But what I need is that it references the label depending on a:
and b:
, where I define the displayed name. For example: All labels having an a:
should be referenced as "Car X" and all labels having a b:
should be referenced as "Truck X" even though they are both a section.
Note: I do not want to change the counter, only the word that is displayed when referencing depending on the label's "namespace"!
Is cleveref
able to do this alone or do I have to build some custom solution (probably with prettyref
)?
Best Answer
Rather than give special meaning to items based on the labels' "prefixes" (
a:
,b:
, ...), I'd use a feature that's already provided by thecleveref
package: use the optional argument of the\label
command to override an item's default cross-referencing name.In the following example, I first inform
cleveref
about the singular and plural forms of items called "car" and "truck", and then use the optional arguments of the\label
commands to informcleveref
that the corresponding sections' "names" are "car" and "truck" rather than "section". (Thehyperref
package is loaded and the optionnameinlink
is specified merely to make the output ofcleveref
immediately visible.)