同一列表中的不同枚举

同一列表中的不同枚举

我想创建一个独特的列表,其中有两个不同的枚举,一个枚举用于每个演示,另一个枚举用于定义。类似的东西:

1)皮波的防守

2)冥王星的防御

[1] 证明布鲁托是皮波的狗

3)托波利诺防御

[2] 证明托波利诺和皮波是朋友

代码的想法如下:

\begin{enumerate} 
\item_def Def. of Pippo
\item_def Def. of Pluto
\item_proof Prove that Pluto is the dog of Pippo
\item_def Def. of Topolino
\item_proof Prove that Topolino and Pippo are friends
\end{enumerate}

答案1

另外,如果您希望避免使用 enumitem 包*,这可能会有用。

我不知道您是否想要缩进 - 如果是这样的话,您可以在定义中留出一些间距。

\newcounter{enumcounter} % Used to reset counters - if you've only two new itemtypes,
                         % probably as easy to reset them explicitly, but for more this
                         % is more efficient
\newcounter{defcount}[enumcounter] % Counts your definition items,  resets every time enumcounter increments
\newcounter{proofcount}[enumcounter]

\newenvironment{myenumerate}{\begin{description}\stepcounter{enumcounter}}{\end{description}}
% defined a new environment, which uses description instead of enumerate or itemize, to avoid the pre-existing
% counters. The spacing is not identical, granted.

\newcommand*{\itemdef}{\item\addtocounter{defcount}{1}(\thedefcount) } % increments the counter, describes item look 
\newcommand*{\itemproof}{\item\addtocounter{proofcount}{1}[\theproofcount] }

\begin{document}
Here is an example:
\begin{myenumerate} 
\itemdef Def. of Pippo
\itemdef Def. of Pluto
\itemproof Prove that Pluto is the dog of Pippo
\itemdef Def. of Topolino
\itemproof Prove that Topolino and Pippo are friends
\end{myenumerate}

And another list of things to check that counters reset:
\begin{myenumerate}
\itemproof Blah
\itemdef Bleep
\itemproof Bloop
\end{myenumerate}
And another line to check that vertical spacing is fine.

在此处输入图片描述

*我意识到这里每个人都喜欢它,这很公平,但是由于与我们的设置冲突,它是进入我们的生产编辑队列时必须被删除的首批软件包之一。

答案2

类似这样的操作应该可以满足您的要求。该enumitem软件包允许您轻松创建自定义列表,并且可以指定要恢复的列表。在当前上下文中,由于恢复的列表位于定义列表内,因此其计数器将位于该列表的本地。enumitem有关间距参数等,请参阅文档(或网站上的其他问题)。

\documentclass{article}
\usepackage{enumitem}
\newlist{defn}{enumerate}{1}
\newlist{demo}{enumerate}{1}
\setlist[defn]{label={\arabic*)}}
\setlist[demo]{label={[\arabic*]},resume}
\begin{document}
\begin{defn}

\item Def. of Pippo

\item Def. of Pluto

\begin{demo}
\item Prove that Pluto is the dog of Pippo
\end{demo}

\item Def. of Topolino

\begin{demo}
\item Prove that Topolino and Pippo are friends
\end{demo}
\end{defn}
\end{document}

代码输出

相关内容