考虑以下代码:
\documentclass{article}
\usepackage{enumitem}
\setlist[enumerate,1]{label = \bfseries \Alph*.}
\setlist[enumerate,2]{label = \bfseries \Alph{enumi}.\arabic*}
\setlist[enumerate,3]{label = \bfseries \Alph{enumi}.\arabic{enumii}.\alph*.}
\begin{document}
\begin{enumerate}
\item
\begin{enumerate}
\item
\begin{enumerate}
\item
\item
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{document}
有没有办法让它\item
检测到它后面跟着另一个enumerate
环境,这样它就不会打印它的标签?然后我可以得到类似的东西:
[3rd level indent]A.1.a
[3rd level indent]A.1.b
我希望该解决方案与之兼容enumitem
。
答案1
我希望以下内容能满足您的需求:
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newcommand\remlabels{\if@inlabel\setbox\@labels=\hbox{}\fi}
\makeatother
\setlist[enumerate,1]{before = \remlabels, label = \Alph*.}
\setlist[enumerate,2]{before = \remlabels, label = \Alph{enumi}.\arabic*}
\setlist[enumerate,3]{before = \remlabels, label = \Alph{enumi}.\arabic{enumii}.\alph*.}
\begin{document}
\begin{enumerate}
\item 1st
\item
\begin{enumerate}
% \item 2nd
\item
\begin{enumerate}
\item
\item
\end{enumerate}
\end{enumerate}
\item 3r
\end{enumerate}
\end{document}
答案2
您可以重新定义\item
宏来提前查看\begin{enumerate}
。以下代码并不漂亮,但确实可以做到这一点:
\documentclass{article}
\usepackage{enumitem}
\usepackage{ifthen}
\setlist[enumerate,1]{label = \bfseries \Alph*.}
\setlist[enumerate,2]{label = \bfseries \Alph{enumi}.\arabic*}
\setlist[enumerate,3]{label = \bfseries \Alph{enumi}.\arabic{enumii}.\alph*.}
\makeatletter
\let\@lditem=\item
\def\n@witem\begin#1{%
\ifthenelse{\equal{#1}{enumerate}}{%
% Use empty label but step the counter
\refstepcounter{\@listctr}\@lditem[]\begin{#1}%
}{%
\@lditem\begin{#1}%
}%
}
\def\item{%
\@ifnextchar\begin{%
% Then check for {enumerate}
\n@witem
}{%
\@lditem
}%
}
\makeatother
\begin{document}
\begin{enumerate}
\item
\item[ZZ]
\item
\begin{enumerate}
\item
\begin{enumerate}
\item
\item
\end{enumerate}
\item
\begin{equation}
1+1=2
\end{equation}
\end{enumerate}
\end{enumerate}
\end{document}
答案3
我不确定,但我想你的意思是你想要
\documentclass{article}
\usepackage{enumitem}
\setlist[enumerate,1]{label = \bfseries \Alph*.}
\setlist[enumerate,2]{label = \bfseries \Alph{enumi}.\arabic*}
\setlist[enumerate,3]{label = \bfseries \Alph{enumi}.\arabic{enumii}.\alph*.}
\makeatletter
\def\@trivlist{%
\if@noskipsec \leavevmode \fi
\@topsepadd \topsep
\ifvmode
\advance\@topsepadd \partopsep
\else
\unskip \par
\fi
\if@inlabel
\@noparitemtrue
\setbox\@labels\hbox{}%
\@noparlisttrue
\else
\if@newlist \@noitemerr \fi
\@noparlistfalse
\@topsep \@topsepadd
\fi
\advance\@topsep \parskip
\leftskip \z@skip
\rightskip \@rightskip
\parfillskip \@flushglue
\par@deathcycles \z@
\@setpar{\if@newlist
\advance\par@deathcycles \@ne
\ifnum \par@deathcycles >\@m
\@noitemerr
{\@@par}%
\fi
\else
{\@@par}%
\fi}%
\global \@newlisttrue
\@outerparskip \parskip}
\begin{document}
\begin{enumerate}
\item
\begin{enumerate}
\item
\begin{enumerate}
\item
\item
\end{enumerate}
\end{enumerate}
\item hmmm
\end{enumerate}
\end{document}