1

I want to have labels that are a composition of consecutive numbering combined with a static value (character). Something like R1, R2, ...

More specificly, I want to have a list of requirements, which I can then reference in the text as "R77", "R4.12" and so on

I have a theorem defined

\newtheoremstyle{requirement}%
{12pt}% Space above
{10pt}% Space below
{}% Body font
{}% Indent amount
{\bfseries\large}% Theorem head font
{}% Punctuation after theorem head
{\newline}% Space after theorem head
{\thmname{#1}\thmnumber{ #2:}\thmnote{ #3}}% Theorem head spec

\theoremstyle{requirement}
\newtheorem{requirement}{Requirement}

\theoremstyle{requirement}
\newtheorem{subrequirement}{Requirement}[requirement]

This does the trick, and when I use it in my doc as

\begin{requirement}[my requirement]
\label{sec:requirements.requirement8}
some text
\end{requirement}

I have a nicely numbered label that I can reference via \ref{...}. Now I want that numbering to have a letter "R" in front instead of simply a number. Can't find an option to solve this. Any suggestions?

Desired output would look something like this:

Requirement R2: xyz
bla

...

As defined in R2 ...
  • 2
    \renewcommand{\therequirement}{R\arabic{requirement}} should work, after \newtheorem .... This will label the environment as well, of course. If this is not desired, we need more action. Please do not post such fragments only, in addition – user31729 Jan 6 '18 at 19:39
  • Thanks for the quick response. Seems NOT to work sadly. It outputs "R0[name]" (thats a zero after the R) and ignores everything defined in the theoremstyle. Moreover, all ref-commands just display the number of the chapter/section. – Xenonite Jan 6 '18 at 19:45
  • 1
    Then post a compilable example... having a small document my proposition works out of the box – user31729 Jan 6 '18 at 19:47
  • Also using numbers (8 here) in label names is not recommended -- it is error prone as soon as the order of environments etc. changes. – user31729 Jan 6 '18 at 19:53
  • 1
    Natürlich funktioniert es ... – user31729 Jan 6 '18 at 20:04
2

Just add

\renewcommand{\therequirement}{R\arabic{requirement}}% Add prefix to (sub-)requirements

after defining your requirement theorem. Since the subrequirement environment counter is defined to be "dependent" on the requirement counter, the prefix will be carried through to that environment counter as well.

enter image description here

\documentclass{article}

\usepackage{amsthm}

\newtheoremstyle{requirement}%
  {12pt}% Space above
  {10pt}% Space below
  {}% Body font
  {}% Indent amount
  {\bfseries\large}% Theorem head font
  {}% Punctuation after theorem head
  {\newline}% Space after theorem head
  {\thmname{#1}\thmnumber{ #2:}\thmnote{ #3}}% Theorem head spec

\theoremstyle{requirement}
\newtheorem{requirement}{Requirement}
\newtheorem{subrequirement}{Requirement}[requirement]% subrequirement depends on requirement

\renewcommand{\therequirement}{R\arabic{requirement}}% Add prefix to (sub-)requirements

\begin{document}

\setcounter{requirement}{76}% Just for this example
\begin{requirement}[my requirement]
  \label{req:requirement}
  Some main requirement.
\end{requirement}

As defined in~\ref{req:requirement}, \ldots

\setcounter{requirement}{4}\setcounter{subrequirement}{11}% Just for this example
\begin{subrequirement}[my subrequirement]
  \label{req:subrequirement}
  Some sub-requirement.
\end{subrequirement}

As defined in~\ref{req:subrequirement}.

\end{document}

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.