6

I would like to have an environment, let's call it nested, which produces output like

Case 1: top level item 1
Case 2: top level item 2
Case 2.1: nested item 1
Case 2.2: nested item 2
Case 2.2.1: even nestier item 1
Case 2.3: just nested again
Case 3: and toplevel to top it off

from code that either looks like nested enumerate's, i.e.

\begin{nested}
\item top level item 1
\item top level item 2
      \begin{nested}
      \item nested item 1
      \item nested item 2
            \begin{nested}
            \item even nestier item 1
            \end{nested}
      \item just nested again
      \end{nested}
\item and toplevel to top it off
\end{nested}

or from code that looks, well, like nested environments:

\begin{nested} top level item 1 \end{nested}
\begin{nested} top level item 2 
    \begin{nested} nested item 1 \end{nested}
    \begin{nested} nested item 2 
            \begin{nested} even nestier item 1 \end{nested}
    \end{nested}
    \begin{nested} just nested again \end{nested}
\end{nested}
\begin{nested} and toplevel to top it off \end{nested}

In fact, I don't much care how the code has to look at all, as long as the numbering on the cases is done automatically. I tried to implement both of the above, however, and I could not figure it out at all. Is there a way to achieve this?

1 Answer 1

8
\documentclass{scrartcl}
\usepackage{enumitem}
\SetLabelAlign{Case}{Case #1:\hfil}
\newlist{nested}{enumerate}{5}
\setlist[nested]{nosep,leftmargin=0pt,labelwidth=*,align=Case,label*=.\arabic*}
\setlist[nested,1]{label=\arabic*}

\begin{document}
\begin{nested}
\item top level item 1
\item top level item 2
      \begin{nested}
      \item nested item 1
      \item nested item 2
            \begin{nested}
            \item even nestier item 1
            \end{nested}
      \item just nested again
      \end{nested}
\item and toplevel to top it off
\end{nested}


\end{document}
4
  • The vertical spacing seems a bit off...
    – jub0bs
    Mar 7, 2013 at 11:43
  • 1
    That's the standard spacing in enumerate. But you can reset it too: see the documentation of enumitem - the values depends on your actual class, and as you didn't give a complete example I didn't bother. Mar 7, 2013 at 11:46
  • I am not worried about vertical spacing, but is there a way to get rid of the final period? Currently it's displaying as Case 2.2.: when I would like it to be Case 2.2:. +1 anyway, this is essentially it. Mar 7, 2013 at 12:09
  • @JeskoHüttenhain: I have edited the code to remove the dot and the vertical spacing. Mar 7, 2013 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .