我想要一个环境,我们称之为nested
,它产生如下输出
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
从代码中任何一个看起来像嵌套enumerate
的,即
\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}
或者从看起来像嵌套环境的代码中:
\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}
事实上,我根本不关心代码看起来如何,只要案例上的编号是自动完成的即可。然而,我尝试实现上述两种方法,却完全搞不懂。有办法实现这一点吗?
答案1
\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}