需求列表,需求文本列表问题

需求列表,需求文本列表问题

我希望我的文档中的“需求”有编号。然后我想要有需求列表,但不仅有需求编号和相应的页面/部分,还有它们的文本。

我尝试过:

\newtheorem{requirement}{Req.}

\begin{requirement}
first requirement
\end{requirement}

some text 

\begin{requirement}
second requirement
\end{requirement}

但我无法创建需求列表。

我尝试了解决方案(我认为存在同样的问题): 目录格式的自定义假设列表

当我使用thm工具我得到了与使用包相同的结果定理 我是说:

Req. ...... 1
Req ....... 2

ETC。

虽然我想要的是类似这样的东西:

first requirement ..... 1
second requirement .... 2

ETC。

我也在考虑另一种解决方案,我需要的是克隆“图形”环境并克隆图形表,然后我可以在标题中保留需求。但是图形是一个浮点数,这不是我想要的。

我知道可以使用括号 [],但是我必须复制相同的文本,一个在 [] 外面。

非常感谢,
亚当

第一次尝试:

\documentclass{book}

\usepackage{amsthm}
\renewcommand{\listtheoremname}{List of Requirements}
\newtheorem{requirement}{Req.}

\begin{document}
\listoftheorems{requirement}

\begin{requirement}
first requirement
\end{requirement}

some text.

\begin{requirement}
second requirement
\end{requirement}

\end{document}

第二次尝试:

\documentclass{book}

\usepackage{amsthm}
\usepackage{thmtools}
\declaretheorem[numberwithin=chapter]{requirement}

\renewcommand{\listtheoremname}{List of Requirements}



\begin{document}

\listoftheorems[ignoreall,show={requirement}]


\begin{requirement}
first requirement
\end{requirement}

some text.

\begin{requirement}
second requirement
\end{requirement}


\end{document}

答案1

您已经有一段时间没有得到答案了,所以我想我会尝试拼凑一个自定义解决方案。这可能需要根据您的具体需求进行一些调整,但它应该可以工作。基本上,我为需求创建了一个自定义环境,将其文本的副本保存到文件中.aux\listofrequirements然后宏只需从中读取它们.aux。(当然,这至少需要两次 LaTeX 传递。)

以下是一个记录示例:

\documentclass{book}

%% This package will make dealing with the ``requirements'' environment a lot easier:
\usepackage{environ}

%% This counter is used to track the number of requirements:
\newcounter{requirements}
\setcounter{requirements}{0}

%% This is a macro that gets called by the .aux file to load in data.
\gdef\savedreq#1#2{\expandafter\gdef\csname req#1\endcsname{#2}}

%% This macro will save the given requirement to the .aux file so we will have it during the next LaTeX pass to put in the list:
\makeatletter
    \def\recordrequirement#1{\immediate\write\@mainaux{\string\savedreq{\the\value{requirements}}{#1}}}
\makeatother

\NewEnviron{requirement}{
  \noindent
  \begingroup
    %% Increment the requirement counter
    \refstepcounter{requirements}
    %% Here is the ``Req.'' text:
    \textbf{Req.~\arabic{requirements}}
    %% Make a label that we can use to refer to this counter:
    \label{req:\arabic{requirements}}
    %% Next, save this requirement to the .aux file so we will have it during the next LaTeX pass to put in the list:
    \recordrequirement{\BODY}
    %% We will make the remainder italic:
    \it
    \BODY
  \endgroup
}

\newcommand{\listofrequirements}{
  %% First, we need to make sure that this is not the first LaTeX pass (i.e., that all of the information has already been recorded to the .aux file):
  \expandafter\ifx\csname totalreqsplusone\endcsname\relax
    Please run \LaTeX\ again to populate this list!
  \else
    \begingroup
      %% This \reqi counter is what we are going to use to iterate over the requirements:
      \newcount\reqi
      \reqi=0
      \loop
        \advance\reqi by 1
      \ifnum\reqi<\totalreqsplusone
        %% The requirement numbered \reqi exists!
        \noindent\textbf{\the\reqi} \csname req\the\reqi\endcsname\leaders\hbox to 1em{\hss.\hss}\hfill\pageref{req:\the\reqi}\\
      \repeat
    \endgroup
  \fi
}

%% At the end of the document, we need to record to the .aux the total number of requirements!
\makeatletter
\AtEndDocument{
  \refstepcounter{requirements}
  \immediate\write\@mainaux{\string\xdef\string\totalreqsplusone{\the\value{requirements}}}
}
\makeatother

\begin{document}

\section*{List of Requirements}

\listofrequirements

\section*{Requirements}

\begin{requirement}
  First requirement!
\end{requirement}    \begin{requirement}
  Requirement number two!
\end{requirement}

\vfill
\pagebreak

\begin{requirement}
  You can even have very long requirements: Lorem ipsum dolor sit
  amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt
  ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
  nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  consequat. Duis aute irure dolor in reprehenderit in voluptate velit
  esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
  cupidatat non proident, sunt in culpa qui officia deserunt mollit
  anim id est laborum.
\end{requirement}

\end{document}

第一页看起来是这样的: 第一页。

这是第二页: 第二页。

相关内容