Hi I build a customer list environment with a counter, and I'd like to be able to reference the name the label associated with the counter. The code below produces an output similar to this:


  • REQ1 Requirement one
  • REQ2 Requirement two

Another Section

  • We want read "Requirement One" here : Requirements.
  • But instead we get the section name!


\usepackage[bookmarks, colorlinks=true, linkcolor=black, citecolor=black, urlcolor=black]{hyperref}


  { \begin{list}{\textbf{\thereqcount}}{\usecounter{reqcount}} }
  { \end{list} }

  \item \textbf{#1}
  \addcontentsline{toc}{subsection}{\thereqcount \quad #1}


\section{Requirements Section}
  \requirement{Requirement one} \label{req_one} \\
  \requirement{Requirement two} \label{req_two} \\

\section{Another Section}
We want read "Requirement One" here : \nameref{req_one}.
But instead we get the section name.


2 Answers 2


Set \@currentlabelname:

  \addcontentsline{toc}{subsection}{\thereqcount \quad #1}

It's not quite the same thing, but consider the following:

  { \begin{list}{\textbf{\thereqcount}}{} }
  %{ \begin{list}{\textbf{\thereqcount}}{\usecounter{reqcount}} }
  { \end{list} }
  \item \textbf{#1}
  \addcontentsline{toc}{subsection}{\thereqcount \quad #1}

The inclusion of \refstepcounter means that the value of the reqcount counter becomes the thing that \label now picks up (rather than the argument of \section, which will have been the last thing that invoked \refstepcounter).

After this, \ref{req_one} expands to "REQ1". Getting \nameref to do the same is presumably not far away (ie, exercise for reader territory!)

  • 1
    Responding to Ulrike's suggestion: \refstepcounter ultimately results in setting \@currentlabel (though with hyperref being part of the game, that's a biiig 'ultimately'). I suspect that \@currentlabelname is a hyperref addition, to support \nameref. Oct 27, 2010 at 9:23

You must log in to answer this question.

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