3

I have a table of requirements that have an ID associated with each one, I'm doing this via:

\stepcounter{functionalrequirements}FR\arabic{functionalrequirements}

I'm wondering if there is a way to do for example something like:

\stepcounter{functionalrequirements}FR\arabic{functionalrequirements}\label{requirement-user-interface}

and then reference like:

As seen in requirement \ref{requirement-user-interface}
rcjsdev
  • 175

1 Answers1

2

Perhaps the following template might suit your needs:

enter image description here

\documentclass{article}
\newcounter{functionalrequirement}
\renewcommand{\thefunctionalrequirement}{FR\arabic{functionalrequirement}}
\newcommand{\newFR}{%
  \refstepcounter{functionalrequirement}%
  \thefunctionalrequirement}

\usepackage{lipsum}% Just for this example
\usepackage{booktabs}
\begin{document}

\lipsum[1]

See, for example,~\ref{fr:first} and~\ref{fr:second} below:
\begin{center}
  \begin{tabular}{ll}
    \toprule
    Reference & Description \\
    \midrule
    \newFR\label{fr:first}  & First \\
    \newFR\label{fr:second} & Second \\
    \bottomrule
  \end{tabular}
\end{center}

\lipsum[2]

\end{document}

Principally you want to use \refstepcounter{<cntr>} to increment the counter. This internally does a \stepcounter{<cntr>}, but also updates LaTeX's referencing mechanism by \the<cntr>. You'll note that I've updated \the<cntr> above to prepend it with FR. You can remove this if you only want the reference to be the number.

Werner
  • 603,163