11

This is a follow-up question to Nested enumerate labels with parent label appended plus a single set of enclosing parentheses

First and foremost, sorry for my English, I'm learning it currently.

Exists any form to set first the numbers, and then enclose it between parenthesis, inside the local environment? I'm making my personal labelist environment, and I've the same problem. First my intended output and next my actual code:

(A) Item 1
  (A.1) Other item
  (A.2) Other item
(B) Item 2
  (B.1) More items.
     (B.1.1) Third level.
     (B.1.2) Other third-level item.
(C) And so on

And here the code of my actual custom environment:

\newcounter{list@depth}
\setcounter{list@depth}{0}

\newenvironment{labelist}{%

   \stepcounter{list@depth}

   \ifnumcomp{\value{list@depth}}{=}{0}{
      \begin{enumerate}[label=\Alpha*]
   }{
      \begin{enumerate}[label*=.\arabic*]
   }

   %% Here enclose the actual format between parenthesis

 }{%
    \ifnumcomp{\value{list@depth}}{=}{1}{
       \setcounter{list@depth}{0}
    }{
        \addtocounter{list@depth}{-1}
    }

    \end{enumerate}
 }

With this code, only I get outputs like this:

A Item 1
  A.1 Other item
  A.2 Other item
B Item 2
  B.1 More items.
     B.1.1 Third level.
     B.1.2 Other third-level item.
C And so on

Because I need only to add parenthesis enclosing labels (an "a posteriori" format).

ABu
  • 1,625

1 Answers1

7

Here's a solution using the enumitem package.

enter image description here

My first attempt used things such as label*=(\Alph*) but of course this produced things such as

(A)(A)

which is not what is wanted.

Below I've created a newlist environment labelist using the \newlist command, and used the \setlist command combined with the counters labelisti (first level), labelistii (second level), labelistiii (third level).

\documentclass{article}

\usepackage{enumitem}
\newlist{labelist}{enumerate}{5}

\setlist[labelist,1]{label*=(\Alph*)}
\setlist[labelist,2]{label=(\Alph{labelisti}.\arabic{labelistii})}
\setlist[labelist,3]{label=(\Alph{labelistii}.\arabic{labelistii}.\arabic{labelistiii})}
\setlist[labelist,4]{label=(\Alph{labelistii}.\arabic{labelistii}.\arabic{labelistiii}.\arabic{labelistiv})}
\setlist[labelist,5]{label=(\Alph{labelistii}.\arabic{labelistii}.\arabic{labelistiii}.\arabic{labelistiv}.\arabic{labelistv})}
\begin{document}


\begin{labelist}
    \item First level
    \begin{labelist}
        \item Second level
        \item Second level
        \begin{labelist}
            \item Third level
            \item Third level
        \end{labelist}
    \end{labelist}
    \item First level
    \begin{labelist}
        \item Second level
        \item Second level
         \begin{labelist}
             \item Third level
             \item Third level
             \begin{labelist}
                    \item Fourth level
                    \item Fourth level
                    \begin{labelist}
                            \item Fifth level
                            \item Fifth level
                        \end{labelist}
                \end{labelist}
         \end{labelist}
    \end{labelist}
\end{labelist}
\end{document}
cmhughes
  • 100,947
  • But this solution has two problems that I want to avoid. First, this is "static", in the sense that you have to know the maximun required depth and to configure the label for each possible depth. My example had depth 3 but it was only an example. Second, this configuration concerns to all document. I want this customization only to this specific environment (labelist). – ABu Nov 01 '12 at 16:03
  • @Peregring-lk You can use my answer and define as many levels you want. – egreg Nov 01 '12 at 16:21
  • But I have to write a new setlist line for each new deepth that I need. And also this solution concerns with any enumerate in the document. – ABu Nov 01 '12 at 16:25
  • @Peregring-lk I've updated my solution; it now only affects your custom list. I agree that it is somewhat 'static' in the sense that you describe, but from a practical point of view, how deep are your lists going to go? – cmhughes Nov 01 '12 at 21:37
  • Five levels of depth as maximum. – ABu Nov 02 '12 at 11:26
  • @Peregring-lk updated – cmhughes Nov 02 '12 at 16:34
  • I've used your solution at the end. But I isn't happy yet xD because I want now to add a prefix passed as paremeter and this is impossible without a custom environment. I have different list in different categories (risks, requirements, etc), and I need this labels to identify differents risks, requirements (RiA1, RiA1.2.2, ReA.1, ReB.1, and so on). I was attempting to develop it as described here: http://tex.stackexchange.com/questions/80125/creating-and-using-commands-counters-which-name-depends-on-other-counter but I had tiny problems and I didn't want to lost more time with this. – ABu Nov 02 '12 at 16:43
  • 1
    @Peregring-lk ok, but how would I have known that from your question? In your question you state what your intended output is, and my solution gives that output! – cmhughes Nov 02 '12 at 16:46
  • @cmhughes By the way, thank you very much for your help. – ABu Nov 02 '12 at 16:46
  • @cmhughes Yes, you're right. Your solution fits perfectly with my described problem. Sorry for not answering you. I've not seen your last comment! – ABu Nov 12 '13 at 16:52