TeX - LaTeX Asked by Mdlc on September 2, 2021
Simple use case, I have a counter for requirements, R1, R2, etc like the one below:
newcounter{requirementcounter}
newcommand{requirement}{refstepcounter{requirementcounter}R.therequirementcounter}
However, when I refer to a counter instance (i.e. requirement{req:a}
by ref{req:a}
) then the ref{}
will only contain the counter value, rather than the custom label in the format of R.value
How can I format the counter reference label?
Here's a small snippet that can do this:
newcounter{reqcount}
newcommand{reqitem}[1]{%
Rref*{#1} refstepcounter{reqcount}label{#1}
}
newcommand{descref}[1]{%
hyperref[#1]{Rref*{#1}}%
}
Example usage:
Here is req: reqitem{reqi:a}
Here is req: reqitem{reqi:b}
Here is reference: descref{reqi:a}, descref{reqi:a}, descref{reqi:b}
Result:
Answered by Mdlc on September 2, 2021
It is sufficient to redefine macro the<counter>
. Then the label
/ref
system will pick it up automatically:
newcounter{requirementcounter}
renewcommand*{therequirementcounter}{Rarabic{requirementcounter}}
...
refstepcounter{requirementcounter}therequirementcounter
label{req:a}
...
ref{req:a}
Answered by Heiko Oberdiek on September 2, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP