3

Within a single enumerate environment from enumitem, I would like to vary the indent level. I've seen examples where leftmargin is configured at the start of the environment, but I would like to change this value at several points, and preferably have the ability to nest arbitrarily-many levels of indentation. The closest solution I've found uses \setlength{\itemindent}{}, but this only indents the first line of each item:

\documentclass[11pt]{article}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}
\setlength{\itemindent}{2em}
\item \underline{Case 1: $n = 1$.}
\setlength{\itemindent}{4em}
\item In this case, $f$ consists of a single literal, so $N(f)$ is true. Let $g = f$. Then, $V(f, g)$ is true because $f$ and $g$ refer to the same formula. Thus, $p(1)$ is true by construction.
\setlength{\itemindent}{2em}
\item \underline{Case 2: $n \ge 2$.}
\setlength{\itemindent}{4em}
\item In this case...
\end{enumerate}

\end{document}

3
  • You could use a \parbox[t]{\linewidth}{...} but you would lose the ability to put pagebreaks in the middle of an item. Commented Feb 12 at 3:43
  • this looks very confusing. Why do you number the "In this case" parts? They are clearly no new items. Commented Feb 12 at 9:55
  • Related post by OP: tex.stackexchange.com/questions/709519/…
    – arz
    Commented Feb 13 at 23:32

2 Answers 2

6

One way to do this would be to use a nested list, and share the top level counter:

\documentclass[11pt]{article}
\usepackage{enumitem}
\newlist{ilist}{enumerate}{2}
\setlist*[ilist]{leftmargin=*}
\setlist*[ilist,1]{label=\arabic*.}
\setlist*[ilist,2]{label=\arabic{ilisti}.,before=\refstepcounter{ilisti}}
\begin{document}

\begin{ilist}
\item \underline{Case 1: $n = 1$.}
\begin{ilist}
\item In this case, $f$ consists of a single literal, so $N(f)$ is true. Let $g = f$. Then, $V(f, g)$ is true because $f$ and $g$ refer to the same formula. Thus, $p(1)$ is true by construction.
\end{ilist}
\item \underline{Case 2: $n \ge 2$.}
\begin{ilist}
\item In this case...
\end{ilist}
\end{ilist}

\end{document}

output of code

7
  • Would there be any way to indent arbitrarily deep?
    – arz
    Commented Feb 12 at 22:57
  • @arz You can add an explicit leftmargin to the second level definition. E.g. \setlist*[ilist,2]{leftmargin=2cm,label=\arabic{ilisti}.,before=\refstepcounter{ilisti}.
    – Alan Munn
    Commented Feb 13 at 1:39
  • 1
    If you want more nesting levels, just change the third argument of the \setlist command to the number of levels you need and then adjust the individual levels as needed. The basic principle is the same.
    – Alan Munn
    Commented Feb 13 at 3:12
  • Thanks for your help. Is there also a way to use the same counter for all nesting levels? (For example, "1." could be followed by indented items "2.", "3.", and "4.", which might be followed by an unindented "5.")
    – arz
    Commented Feb 14 at 0:38
  • @arz Yes, you can basically use the same code for each level. The code I gave will work for level 3 or 4 etc.
    – Alan Munn
    Commented Feb 14 at 3:28
0

I was able to get a working sample for what I wanted using Alan Munn's suggestion along with this answer.

\documentclass[11pt]{article}
\usepackage{enumitem}
\newlist{ilist}{enumerate}{4}
\newif\iffirstlegal\firstlegalfalse
\setlist*[ilist]{leftmargin=*}
\setlist*[ilist,1]{label=\arabic*.}
\setlist*[ilist,2]{label=\arabic*.,
    start=\value{ilisti},
    before*={
        \let\olditemii\item
        \firstlegaltrue
        \def\item{\iffirstlegal\refstepcounter{ilistii}\olditemii\firstlegalfalse\else \refstepcounter{ilisti}\olditemii \fi}
    },
    after*={
        \refstepcounter{ilisti}
        \let\item\olditemii
    }
}
\setlist*[ilist,3]{label=\arabic*.,
    start=\value{ilistii},
    before*={
        \let\olditemiii\olditemii
        \firstlegaltrue
        \def\item{\iffirstlegal\refstepcounter{ilistiii}\olditemiii\firstlegalfalse\else \refstepcounter{ilisti}\refstepcounter{ilistii}\olditemiii \fi}
    },
    after*={
        \refstepcounter{ilisti}\refstepcounter{ilistii}
        \let\olditemii\olditemiii
    }
}
\setlist*[ilist,4]{label=\arabic*.,
    start=\value{ilistiii},
    before*={
        \let\olditemiiii\olditemiii
        \firstlegaltrue
        \def\item{\iffirstlegal\refstepcounter{ilistiv}\olditemiiii\firstlegalfalse\else \refstepcounter{ilisti}\refstepcounter{ilistii}\refstepcounter{ilistiii}\olditemiiii \fi}
    },
    after*={
        \refstepcounter{ilisti}\refstepcounter{ilistii}\refstepcounter{ilistiii}
        \let\olditemiii\olditemiiii
    }
}

\begin{document}

\begin{ilist}
\item A
\begin{ilist}
\item A'
\item A''
\item A'''
\begin{ilist}
\item a'
\item a''
\begin{ilist}
\item $\alpha$'
\item $\alpha$''
\end{ilist}
\end{ilist}
\end{ilist}
\item B
\begin{ilist}
\item B'
\item B''
\begin{ilist}
\item b'
\item b''
\end{ilist}
\end{ilist}
\end{ilist}

\end{document}

You must log in to answer this question.

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