Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I will give an example of what I need exactly. The output should look like the default description list, with numbered labels.

REQ-ABC-001    Lorem Ipsum ...
     if the text is longer than a line, it is indent like normal description-lists.
REQ-ABC-002    Second item
REQ-ABC-003    and so on\label{req:label}

In the text those items should be referable as See~\ref{req:label} resulting in See REQ-ABC-003. This is my actual problem.

The list itself should be displayed by the following LaTeX code:

\begin{reqlist}{abc}
  \item Lorem Ipsum ...
  \item ... 
\end{reqlist}

The parameter describes the inner part of the items' label (REQ is constant). I want to keep the usage very simple.

I have experimented with enumerate/description/list-environments. Each has its pros and cons but all had the same problem. I did not manage to change the output of \ref. When I am using enumitem with \newlist I do not see a way to include the parameter.

Anyone have an idea or a tip for me how to achieve this?


For convenience the display of the counter can be done like this. Just provide a counter.

\newcommand{\arabicThree}[1]{%
\ifthenelse{\value{#1}<10}{%
00\arabic{#1}}{%
\ifthenelse{\value{#1}<100}{%
0\arabic{#1}}{%
\arabic{#1}%
}}}
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

This can be done with the help of the enumitem package; I defined the \threeatdigits command (similar to the kernel's \two@digits command) to add the necessary number of zeroes to the numbers:

\documentclass{article}
\usepackage{enumitem}

% adds zeroes at the left of the number
\newcommand\parameter{}
\def\threeatdigits#1{\ifnum#1<10 00\else\ifnum#1<100 0\fi\fi\number#1}

\usepackage{lipsum}
\newlist{mylist}{enumerate}{4}
\setlist[mylist]{label={REQ-\parameter-\protect\threeatdigits{\arabic*}}, leftmargin=*,
labelsep=*,itemindent=5em}

\newenvironment{reqlist}[1]
  {\renewcommand\parameter{#1}
\begin{mylist}}
  {\end{mylist}}

\begin{document}

As can be seen in~\ref{a}
\begin{reqlist}{ABC}
  \item \lipsum[1]\label{a}
\end{reqlist}

\end{document}

enter image description here

share|improve this answer
    
Thank you so far. Except for the layout, this was one of my tries, but the parameter is still missing as described in the question. Any ideas for that problem? –  Frank Jun 27 '11 at 20:56
    
@Frank: added. See my updated answer. –  Gonzalo Medina Jun 27 '11 at 21:09
    
Am I right, that i need a wrapper environment to change \parameter before beginning the list itself? I guess that is a solution. –  Frank Jun 27 '11 at 21:16
    
@Frank: perhaps you wrote your last comment while I was editing my answer. I had already included the necessary modifications. –  Gonzalo Medina Jun 27 '11 at 22:34
    
Yes, that might be the case. But I have seen it shortly afterwards (while I just started writing it myself in the document). Thank you –  Frank Jun 29 '11 at 21:56
add comment

A variation on Gonzalo's theme; this one shows how to register a counter representation for enumitem

\usepackage{enumitem}

\newlist{reqlist}{enumerate}{1}
\setlist[reqlist]{label=\req*,leftmargin=*,labelsep=*,itemindent=5em}

\newcommand{\req}[1]{\expandafter\inreq\csname c@#1\endcsname}
\newcommand{\inreq}[1]{REQ-ABC-\threedigits{#1}}
\newcommand{\threedigits}[1]{%
  \ifnum#1<100 0\fi\ifnum#1<10 0\fi\number#1\relax}
\AddEnumerateCounter{\req}{\inreq}{REQ-ABC-000}

In this way the code is neater, because it better separates form and contents.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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