3

I may or may not have chosen this format myself, but I'm trying to type up somebody else's work all nicely.

What I would like is to have nested lists with a label format of 1a. 1b. 1c. ... 2a. 2b. 2c. ... etc. However what I don't want is any item 1. 2. etc. In other words I want a list that looks like this:

1a. Lorem
1b. Ipsum
2a. Dolor
2b. Sit
3a. Amet

But not:

1. Lorem ipsum
   1a. Dolor sit amet
   1b. Consectetur adipiscing elit

The latter is easy to produce with enumitem's label* command.

I also don't want to descend to the level of manually labelling each item, I would like to make proper use of counters. However, I'd rather not start cracking open etoolbox if I can help it. This list will be used only once in this document, no other list will have this structure, and I'm not very familiar with nor fond of the LaTeX3 stuff. I'd rather stick with enumitem (I've used that package elsewhere) and simple commands that you'll find in Leslie Lamport's book cause I can understand them.

One thing I tried was setting up a one-use counter for this list only called olist (outer list). I can then redefine \labelenumi to use that counter to make the label. This way, if I manually step olist I have something that resembles a proper list. It's not ideal, but writing \stepcounter{olist} instead of \item isn't so bad and I can still move the items in my list around without having to manually change every item number:

\begin{enumerate}
  \newcounter{olist}\stepcounter{olist}
  \renewcommand{\labelenumi}{\theolist\alph{enumi}.}
  \item Lorem
  \item Ipsum
  \stepcounter{olist}
  \item Dolor
\end{enumerate}

enter image description here

The obvious problem is stepping olist does not reset enumi, so unless I also write \setcounter{enumi}{0} every time I step olist it really seems like this approach is a dead end. I don't think I can make enumi depend on olist, but if that's possible I'd like to know how. Otherwise if anyone can show me how to make enumitem do this nicely I'd be grateful.

3
  • typing the label manually for one list will take three minutes. Is it really worth to think about an automated solution? Nov 9, 2022 at 17:38
  • @UlrikeFischer of course it is:-) Nov 9, 2022 at 17:39
  • @UlrikeFischer I mean despite what I said about LaTeX3 etc. I am nevertheless interested in the hows and whys of the LaTeX I know and would like to know and understand how it can be done properly. Also I haven't got all the way through the document I'm typing up so similar lists may crop up in future, I just wanted to let answerers know that I didn't want anything that would change other lists in the document nor did I want anything too heavy or that I couldn't understand all for the sake of one list. but I might want something similar in future
    – Au101
    Nov 9, 2022 at 17:50

3 Answers 3

4

You can define your own nestedlist and step an outer list counter as needed:

enter image description here

\documentclass{article}

\usepackage{enumitem}

\newlist{nestedlist}{enumerate}{1}% This defines the counter nestedlisti
\setlist[nestedlist]{
  label=\theouterlist\alph*.,
  before=\setcounter{outerlist}{1}}
\newcounter{outerlist}
\newcommand{\stepouterlist}{\stepcounter{outerlist}}
\makeatletter
\@addtoreset{nestedlisti}{outerlist}% Reset nestedlist counter with every change in outerlist counter
\makeatother

\begin{document}

\begin{nestedlist}
  \item Lorem
  \item Ipsum
  
  \stepouterlist
  \item Dolor
  \item Lorem
  \item Ipsum
  
  \stepouterlist
  \item Dolor
  \item Lorem
  
  \stepouterlist
  \item Ipsum
\end{nestedlist}

\end{document}
4

You can mark up as nested lists, you may want to adjust the white space using standard enumitem keys but:

enter image description here

\documentclass{article}

\usepackage{enumitem}

\begin{document}
\begin{enumerate}[label=]
\item
  \begin{enumerate}[label=\arabic{enumi}\alph*]
  \item Lorem
  \item Ipsum
  \end{enumerate}
\item
  \begin{enumerate}[label=\arabic{enumi}\alph*]
  \item Dolor
  \item Sit
  \end{enumerate}
\item
  \begin{enumerate}[label=\arabic{enumi}\alph*]
  \item Amet
  \end{enumerate}
\end{enumerate}
\end{document}
1
  • Thanks David, that was basically my first attempt, but I got a bit lost in the reeds of the 'standard enumitem keys' and gave the approach up as a bad job. Do you know what values I would need to use to make these labels line up with those in a plain vanilla ordinary enumerate?
    – Au101
    Nov 9, 2022 at 17:53
3

enter image description here

\documentclass{article}
\usepackage{expl3}
\usepackage{xparse}
\usepackage{enumitem}

\ExplSyntaxOn

\int_new:N \g_nenum_level_int
\int_gset:Nn \g_nenum_level_int {0}


\DeclareDocumentEnvironment{nestedenum}{}{
  % increment level counter
  \int_gincr:N \g_nenum_level_int
  \begin{enumerate}[
    label={\int_use:N \g_nenum_level_int \alph* .}, 
    leftmargin=0em,
    itemsep=0pt,
    parsep=0pt,
    partopsep=0pt,
    topsep=0pt
    ] 
  
}{
  \end{enumerate}
  \int_gdecr:N \g_nenum_level_int
}

\ExplSyntaxOff

\begin{document}

\begin{nestedenum}
\item First level (1)
\item First level (2)
   \begin{nestedenum}
    \item Second level (1)
    \item Second level (2)
       \begin{nestedenum}
        \item Third level (1)
        \item Third level (2)
      \end{nestedenum}
    \item Second level (3)
    \item Second level (4)
  \end{nestedenum}
\item First level (3)
\item First level (4)
\end{nestedenum}

\vspace*{2em}

\begin{nestedenum}
\item First level (1)
\item First level (2)
   \begin{nestedenum}
    \item Second level (1)
    \item Second level (2)
       \begin{nestedenum}
        \item Third level (1)
        \item Third level (2)
      \end{nestedenum}
    \item Second level (3)
    \item Second level (4)
  \end{nestedenum}
\item First level (3)
\item First level (4)
\end{nestedenum}


\end{document}
4
  • Doesn't quite avoid LaTeX3 :P But it's certainly very clever and it certainly deserves a +1. I don't know what any of it means or does, but nobody can accuse it of not doing the job!
    – Au101
    Nov 9, 2022 at 17:57
  • You can add the itemsep=0pt,parsep=0pt,partopsep=0pt,topsep=0pt keys to David Carlisle's solution, they are basically the same
    – Alan Xiang
    Nov 9, 2022 at 17:58
  • Despite the naming rules look scary in LaTeX3, the idea behind it is not very difficult to understand. I defined a integer variable named \g_nenum_level_int; I call the \int_gincr:N command to increment it; I call the \int_gdecr:N command to decrement it. These operations can all be done in LaTeX2e with \numexpr or other similar techniques. I am just more used to using LaTeX3.
    – Alan Xiang
    Nov 9, 2022 at 18:01
  • Thanks for the explanation it does help!
    – Au101
    Nov 9, 2022 at 18:05

You must log in to answer this question.

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