在一个枚举内更改缩进级别

在一个枚举内更改缩进级别

在 的单个enumerate环境中enumitem,我想改变缩进级别。我见过leftmargin在环境开始时配置的示例,但我想在几个点更改此值,并且最好能够嵌套任意多个缩进级别。我找到的最接近的解决方案是使用\setlength{\itemindent}{},但这只会缩进每个项目的第一行:

\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}

答案1

一种方法是使用嵌套列表并共享顶级计数器:

\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}

代码输出

答案2

我能够使用 Alan Munn 的建议以及回答。

\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}

相关内容