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}

arz
  • 157
  • You could use a \parbox[t]{\linewidth}{...} but you would lose the ability to put pagebreaks in the middle of an item. – John Kormylo Feb 12 '24 at 03:43
  • this looks very confusing. Why do you number the "In this case" parts? They are clearly no new items. – Ulrike Fischer Feb 12 '24 at 09:55
  • Related post by OP: https://tex.stackexchange.com/questions/709519/hyperref-conflicting-with-enumitem – arz Feb 13 '24 at 23:32

2 Answers2

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

Alan Munn
  • 218,180
  • Would there be any way to indent arbitrarily deep? – arz Feb 12 '24 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 Feb 13 '24 at 01: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 Feb 13 '24 at 03: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 Feb 14 '24 at 00: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 Feb 14 '24 at 03:28
  • Sorry, I'm doing a very poor job of describing what I want. The code you gave (copy/pasting a level 3) currently produces https://imgur.com/Z7VsNyz. I would like
    1. A, 2. A', 3. A'', 4. a', 5. a'', etc.
    – arz Feb 14 '24 at 13:51
  • Nevermind, I seem to have gotten it to work (see my answer). Thanks again. – arz Feb 14 '24 at 14:43
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}

arz
  • 157