4

This question already has an answer here:

I want to label my enumeration like SOMETEXT01, SOMETEXT02, ..., SOMETEXT10, etc. I read through a couple of questions and know how to create a counter that adds in leading zeros.

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

How can I use it with the labeling?

\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}

Output looks like

/FR1/ Do this

You should always be able to do this.

/FR2/ Validate

After doing this, the user should be able to validate.

marked as duplicate by clemens, Claudio Fiandrino, lockstep, Mensch, Guido Sep 10 '13 at 10:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

You can define a counter representation command \twodigits using the kernel command \two@digits internally. It can be made known to enumitem with \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}

enter image description here

  • Thank you! Could you please explain a little bit more? E.g. What exactly is the \csname c@#1 for, I never came across sth like that – mike Jun 10 '13 at 11:34
  • 1
    Every counter <counter> has an internal command \c@<counter> that stores its number, \c@section for the section counter etc. \csname ...\endcsname builds a command sequence from the tokens in between. \twodigits{counter} will in effect call \two@digits\c@counter. – clemens Jun 10 '13 at 11:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.