我想要由连续编号和静态值(字符)组成的标签。例如 R1、R2、...
更具体地说,我想要一个需求列表,然后我可以在文本中将其引用为“R77”,“R4.12”等
我有一个定义定理
\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]
这很管用,当我在文档中使用它时
\begin{requirement}[my requirement]
\label{sec:requirements.requirement8}
some text
\end{requirement}
我有一个编号整齐的标签,可以通过 引用\ref{...}
。现在我希望该编号前面有一个字母“R”,而不是简单的数字。找不到解决此问题的选项。有什么建议吗?
期望的输出看起来会像这样:
Requirement R2: xyz
bla
...
As defined in R2 ...
答案1
只需添加
\renewcommand{\therequirement}{R\arabic{requirement}}% Add prefix to (sub-)requirements
在定义定理之后requirement
。由于subrequirement
环境计数器被定义为“依赖于”计数器requirement
,因此前缀也将传递到该环境计数器。
\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}