I'm building a software requirements document and using my own set of counters to generate unique requirement identifiers. I'm also grouping different requirements into longtables, e.g.

\begin{longtable}{l p{4in}}
F\FormatCntr{ModuleCntr}-\FormatCntr{ComponentCntr} & Some Requirements Category\stepcounter{RequirementCntr}\\
F\FormatCntr{ModuleCntr}-\FormatCntr{ComponentCntr}.\FormatCntr{RequirementCntr} & Specific software requirement

This will generate something like:

F00-01 Some Requirements

F00-01-01 Specific software requirement.

Now at some point later in the text, I want to cross-reference back to that specific requirement. I can use \hypertarget and \hyperlink and say something like "See this requirement" and have "this" link back to the referenced requirement but it would be much more elegant to say "See requirement F00-01-01" but "F00-01-01" must be linked automatically due to the dynamic nature of the counters.


You can use the normal \label/\ref system. If a counter is increased via \refstepcounter, then an anchor is placed at this location and the counter appearance and the anchor name are made available for the next \label. Then \ref, \pageref can be used to reference the label. For free link texts \hyperref with the optional argument can be used:

\hyperref[<label name>]{<free link text>}

The counter value could also be used for an automatic label name, but then the label names in references do not get updated, if the counter value changes.

|improve this answer|||||
  • I think I can see how the normal label/ref system could be used for individual counters but I'm looking to automatically generate hyperlinked text that is composed of the values of multiple independent counters. – user36792 Sep 16 '13 at 20:38
  • @user36792: subsection is an example of an counter that often comes with the values of other counters (section, chapter). The only important issue for hyperref is the uniqueness of the anchor names. Usually it makes use of \the<counter>, but prefers \theH<counter>, if it exists. Thus the latter macro can be provided to get uniqueness, if \the<counter> is not unique. – Heiko Oberdiek Sep 16 '13 at 20:47

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.