同一列表中的不同枚舉

同一列表中的不同枚舉

我想製作一個獨特的列表,其中有兩個不同的枚舉,一個枚舉用於每個演示,另一個枚舉用於定義。就像是:

1) 定義。皮波的

2) 定義。冥王星的

[1] 證明Pluto是Pippo的狗

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}

程式碼的輸出

相關內容