我希望制作一个包含多个enumerate
环境且不同标题交织在一起的文档,以便最终结果看起来像这样:
但是,每次我想切换时,我都会打开新的enumerate
环境(代码如下),结果间距不均匀(A2
和之间的间隙大于和B1
之间的间隙)。有没有更好和/或更简单的方法来做到这一点?理想情况下,我希望能够说类似的话A1
A2
\item[A] Lorem ipsum...
\item[A] Ut purus...
\item[B] Curabitur...
我尝试举一个我需要的例子:
\documentclass{article}
\usepackage[margin=1.5cm,includehead,includefoot]{geometry}
\usepackage{enumitem}
\newcounter{counta}
\newcounter{countb}
\newcounter{countc}
\begin{document}
\begin{enumerate}[label=A{\arabic*}]
\setcounter{enumi}{\value{counta}}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\item Ut purus elit vestibulum ut, placerat ac, adipiscing vitae.
\setcounter{counta}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label=B{\arabic*}]
\setcounter{enumi}{\value{countb}}
\item Curabitur dictum gravida mauris.
\item Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
\setcounter{countb}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label={A\arabic*}]
\setcounter{enumi}{\value{counta}}
\item Donec vehicula augue eu neque.
\setcounter{counta}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label={C\arabic*}]
\setcounter{enumi}{\value{countc}}
\item Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
\setcounter{countc}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label=B{\arabic*}]
\setcounter{enumi}{\value{countb}}
\item Mauris ut leo.
\setcounter{countb}{\value{enumi}}
\end{enumerate}
\end{document}
答案1
更好的方法使用新定义的\Xitem
这里,定义\Xitem
采用可选列表指示符。我还定义了Xenumerate
环境,它将在输入时重置计数器。
\documentclass{article}
\usepackage[margin=1.5cm,includehead,includefoot]{geometry}
\usepackage{enumitem}
\newcounter{countA}
\newcounter{countB}
\newcounter{countC}
\newcommand\Xitem[1][A]{\stepcounter{count#1}\item[#1\arabic{count#1}]}
\newenvironment{Xenumerate}{%
\setcounter{countA}{0}%
\setcounter{countB}{0}%
\setcounter{countC}{0}%
\begin{enumerate}}{\end{enumerate}}
\begin{document}
\begin{Xenumerate}
\Xitem Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\Xitem Ut purus elit vestibulum ut, placerat ac, adipiscing vitae.
\Xitem[B] Curabitur dictum gravida mauris.
\Xitem[B] Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
\Xitem Donec vehicula augue eu neque.
\Xitem[C] Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
\Xitem[C] Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
\Xitem[B] Mauris ut leo.
\end{Xenumerate}
\end{document}
原始方式使用 OP 的基本方法
添加partopsep=0pt
到每个列表似乎可以消除不均匀的间距。
\documentclass{article}
\usepackage[margin=1.5cm,includehead,includefoot]{geometry}
\usepackage{enumitem}
\newcounter{counta}
\newcounter{countb}
\newcounter{countc}
\begin{document}
\begin{enumerate}[label=A{\arabic*},partopsep=0pt]
\setcounter{enumi}{\value{counta}}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\item Ut purus elit vestibulum ut, placerat ac, adipiscing vitae.
\setcounter{counta}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label=B{\arabic*},partopsep=0pt]
\setcounter{enumi}{\value{countb}}
\item Curabitur dictum gravida mauris.
\item Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
\setcounter{countb}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label={A\arabic*},partopsep=0pt]
\setcounter{enumi}{\value{counta}}
\item Donec vehicula augue eu neque.
\setcounter{counta}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label={C\arabic*},partopsep=0pt]
\setcounter{enumi}{\value{countc}}
\item Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
\item Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
Pellentesque habitant morbi tristique senectus et netus et malesueda fames ac turpis egestas.
\setcounter{countc}{\value{enumi}}
\end{enumerate}
\begin{enumerate}[label=B{\arabic*},partopsep=0pt]
\setcounter{enumi}{\value{countb}}
\item Mauris ut leo.
\setcounter{countb}{\value{enumi}}
\end{enumerate}
\end{document}