我在自定义环境中使用环境。通常,在启动列表后,enumerate
可以通过添加属性来恢复列表。但是,在我的自定义环境中,该属性被忽略。这导致每次都启动一个新列表的行为。我的目标自定义环境包含更多代码,但为了简单起见,我将其精简到重要部分。resume
resume
\documentclass{scrartcl}
\usepackage{enumitem}
\usepackage{xifthen}
\newenvironment{questionlist}
{
\begin{enumerate}[{resume}]} % should lead to a resuming list
{\end{enumerate}
}
\begin{document}
first part
\begin{questionlist}
\item first
\item second
\end{questionlist}
second part % currently, produces a new list starting from 1 again and not from 3
\begin{questionlist}
\item third
\item fourth
\end{questionlist}
\end{document}
答案1
我已经更改了你的代码
\newenvironment{questionlist}
{
\begin{enumerate}[{resume}]} % should lead to a resuming list
{\end{enumerate}
}
到
\newenvironment{questionlist}
{
\enumerate[resume]
}
{
\endenumerate
}
并且它有效。
\documentclass{scrartcl}
\usepackage{enumitem}
\usepackage{xifthen}
\newenvironment{questionlist}
{
\enumerate[resume]
}
{
\endenumerate
}
\begin{document}
first part
\begin{questionlist}
\item first
\item second
\end{questionlist}
second part % currently, produces a new list starting from 3
\begin{questionlist}
\item third
\item fourth
\end{questionlist}
\end{document}
答案2
这是 Sebastianos 答案的替代方案,使用enumitem
内置功能创建新列表,然后将其添加resume
为该列表的属性
\documentclass{article}
\usepackage{enumitem}
\newlist{questionlist}{enumerate}{2}
\setlist[questionlist]{
label=\arabic*.,
resume
}
\begin{document}
first part
\begin{questionlist}
\item first
\item second
\end{questionlist}
second part % currently, produces a new list starting from 1 again and not from 3
\begin{questionlist}
\item third
\item fourth
\end{questionlist}
\end{document}