如何在列表标签​​中加入计数器

如何在列表标签​​中加入计数器

我想标记我的枚举某些文本01,某些文本02,...,某些文本10,等等。我阅读了几个问题并且知道如何创建一个添加前导零的计数器。

\newcounter{counter}
\newcommand*{\getCount}{%
  \ifnum\value{counter}<10 0\fi%
  \arabic{counter}%
}
\getCount
\setcounter{counter}{10}
\getCount

我该如何将它与标签一起使用?

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{enumitem}
\usepackage{ae}
\usepackage[pdftex]{graphicx}
\usepackage{vmargin}
\usepackage{url}
\usepackage[absolute,overlay]{textpos}
\usepackage[german]{babel}

\newlist{frequirements}{enumerate}{3}
\setlist[frequirements, 1]{labelindent=0pt, label*=\textbf{/FR{\arabic*}/},itemindent=0em,leftmargin=*}


\begin{frequirements}
    \item \textbf{Do this} \\ You should always be able to do this.
    \item \textbf{Validate} \\
    After doing this, the user should be able to validate.
\end{frequirements}

\end{document}

输出看起来像

/FR1/ 执行此操作

你应该总是能够做到这一点。

/FR2/ 验证

完成此操作后,用户应该能够验证。

答案1

\twodigits您可以使用内核命令在内部定义计数器表示命令。可以使用以下命令使它\two@digits为人所知:enumitem\AddEnumerateCounter

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}

% make @ a letter so it can be used in macro names:
\makeatletter
% define the counter representation command \twodigits:
\def\twodigits#1{\expandafter\two@digits\csname c@#1\endcsname}
% in effect \twodigits{counter} will call \two@digits\c@counter,
% where \c@counter is the internal command for the counter
% \two@digits is defined in the kernel as follows:
%     \def\two@digits#1{\ifnum#1<10 0\fi\number#1}

% the enumerate package uses the macro \AddEnumerateCounter
% to make the counter representation commands usable in the `label'
% key. The first argument is the actual command, the second
% the internal version that actually formats the numbers and
% the third an ID for the enumerate package.
\AddEnumerateCounter\twodigits\two@digits{01}

% make @ other again:
\makeatother

\newlist{frequirements}{enumerate}{3}

\setlist[frequirements, 1]{
   labelindent=0pt,
   label*=/FR\twodigits*/,
   font=\bfseries,
   itemindent=0em,
   leftmargin=*}


\begin{document}

\begin{frequirements}
  \item \textbf{Do this} \\ You should always be able to do this.
  \item \textbf{Validate} \\
    After doing this, the user should be able to validate.
\end{frequirements}

\end{document}

在此处输入图片描述

相关内容