(Repost from Stack Overflow)
I'd like to refer to a description list item by name instead of number. To that effect, I've added labels to each item, but when referencing them I only get the name of the section, not of the list item. How can I change it to show a custom label for each item?
\section{Definitions}
\begin{description}
\item [Vehicle\label{itm:vehicle}] Something
\item [Bus\label{itm:bus}] A type of \nameref{itm:vehicle}
\item [Car\label{itm:car}] A type of \nameref{itm:vehicle} smaller than a \nameref{itm:bus}
\end{description}
The result is something like this:
1 Definitions
Vehicle Something
Bus A type of Definitions
Car A type of Definitions smaller than a Definitions
I'd like to have the following:
1 Definitions
Vehicle Something
Bus A type of Vehicle
Car A type of Vehicle smaller than a Bus
An alternative solution would be to use subsections and display them as a definition list. Anyone know how to do it?
The best answer on Stack Overflow referenced a \makeatletter hack:
\makeatletter
\def\namedlabel#1#2{\begingroup
\def\@currentlabel{#2}%
\label{#1}\endgroup
}
\makeatother
...
\section{Definitions}
\begin{description}
\item [Vehicle\namedlabel{itm:vehicle}{Vehicle}] Something
\item [Bus\namedlabel{itm:bus}{Bus}] A type of \ref{itm:vehicle}
\item [Car\namedlabel{itm:car}{Car}] A type of \ref{itm:vehicle} smaller than a \ref{itm:bus}
\end{description}
It works, with the caveat that the links lead back to the section header, not to the list item. It would be nice to use something native which doesn't break \ref.
\refeven works like expected outside of the description environment. – l0b0 Aug 10 '10 at 12:44spacedlowsmallcapsfont? I am usingclassicthesis, where description items are written using this font (the code from the style file:\renewcommand{\descriptionlabel}[1]{\hspace*{\labelsep}\spacedlowsmallcaps{#1}}), so when I am referencing the items I would like them to look the same as in the list. – Elena Nov 20 '13 at 15:45! Use of \\smash doesn't match its definition.– Jonathan Komar Sep 21 '15 at 13:06\edef\@currentlabel{#1\unskip}%instead of just\edef\@currentlabel{#1}%to prevent the appearance of extra space to the right of the text inside the hyperlinks produced by\ref{}. – cgogolin Aug 19 '17 at 12:08