我在使用按顺序编号的文本示例的手稿中遇到了一个奇怪的编号问题。当一个示例演示了某些错误的东西,并且后来需要纠正时,它们会带有后缀 a、b 等等。在这两者之间,恰好有文本和可能的其他示例继续使用原始编号,例如:
(1)...例子...
... 文本 ...
(2a)......不好的例子......
...启发性的文字和例子:
(3)...例如...
... 之后我们可能会回到之前的坏例子 (2a),并展示更正
(2b)......很好的例子......
...恢复正常,还有更多例子:
(4)...例如...
有人问我如何在 LaTeX 中巧妙地做到这一点。我尝试使用 enumitem 包,如下所示,但遇到了麻烦:
\documentclass{article}
\usepackage{enumitem}
\newlist{examples}{enumerate}{1}
\setlist[examples]{label=(\arabic*)}
\newlist{subexamples}{enumerate}{1}
\begin{document}
First an example, which we call 1.
\begin{examples}
\item example
\end{examples}
Then a bad example which we would like to call 2a:
\addtocounter{examplesi}{1}
\begin{subexamples}[series=aname, label=(\theexamplesi\alph*)]
\item example
\end{subexamples}
We learn something new in examples 3 and 4 (with wrong labels):
\begin{examples}[resume]
\item example
\item example
\end{examples}
And we get back to the bad example, which should be 2b:
\begin{subexamples}[resume*=aname]
\item example
\end{subexamples}
\end{document}
上述示例生成标签 1、2a、2、3、3b。目标是 1、2a、3、4、2b。
人们应该能够引用单个项目,并且它应该足够灵活,以便拥有多个“悬挂”示例......
答案1
好吧,我找到了一种方法;虽然不能说它令人满意,但它确实有效。缺点是:您不能将带有后缀的示例和不带有后缀的示例混合在一个列表中,并且后缀 a、b、... 是“硬编码的”,而主计数器是“自动的”。此外,我认为它可以更漂亮,因为引用有点混乱。如下所示:
\documentclass{article}
\usepackage{enumitem}
\newlist{examples}{enumerate}{1}
\setlist[examples]{label=(\arabic*), ref=\arabic*, resume}
\begin{document}
\section{On numbered examples}
First, an example:
\begin{examples}
\item\label{first} \dots example \dots
\end{examples}
This can be referenced as expected: check out (\ref{first}).
Now, a second example which we can elaborate on later is
\begin{examples}[label=(\arabic*a), ref=\arabic*]
\item\label{second} \dots example \dots
\end{examples}
The suffix in (\ref{second}a) hard coded as \verb+label=(\arabic*a)+
in the options for this one example environment.
We learn something new in examples 3 and 4, and use the
environment as is:
\begin{examples}
\item example
\item example
\end{examples}
And we get back to previous example in examples 2b and 2c:
\begin{examples}
\item[(\ref{second}b)] \dots example \dots
\item[(\ref{second}c)] \dots example \dots
\end{examples}
Since \verb+\item+ is used with \verb+[]+ the counter is not
incremented. These are referenced as e.g. \verb+(\ref{second}b)+.
And we test that the counter is as it should be:
\begin{examples}
\item \dots example \dots
\end{examples}
\end{document}