使用 时amsthm
,我希望能够在稍后继续特定的类定理环境(在我的情况下是示例)。继续的环境应具有与之前继续的环境相同的编号;并且在继续的环境完成后,应恢复正常的定理编号。
下面的方法可以实现我想要的效果。有没有更简单或更好的方法——而不必从 LaTeX 转向纯 TeX?
% continue-thm.try
\documentclass[12pt]{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{example}[theorem]{Example}
\newcounter{savedthmcounter}
\newcounter{tobecontinuedthmcounter}
% Invoke \tobecontinued immediately AFTER theorem to be continued
\newcommand{\tobecontinued}{%
\setcounter{tobecontinuedthmcounter}{\value{theorem}}%
\addtocounter{tobecontinuedthmcounter}{-1}}
% Invoke \continue immediately BEFORE continuing theorem that was to be continued
\newcommand{\continue}{%
\setcounter{savedthmcounter}{\value{theorem}}%
\setcounter{theorem}{\value{tobecontinuedthmcounter}}}
% Invoke immediately AFTER done with the continued theorem
\newcommand{\resume}{\setcounter{theorem}{\value{savedthmcounter}}}
\begin{document}
\begin{theorem}% 1
Theorem 1.
\end{theorem}
\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}
%
\tobecontinued
\begin{theorem}% 3
Theorem 3.
\end{theorem}
\begin{theorem}%4
Theorem 4.
\end{theorem}
\begin{proposition}
A proposition.
\end{proposition}
\continue
%
\begin{example}[continued]% 2 again
Example \ref{ex:ex2}, continued.
\end{example}
\resume
\begin{theorem}% 5
Theorem 5.
\end{theorem}
\end{document}
添加
前面的方法不仅适用于amsthm
与article
等,而且当我使用thmtools
和然后\declaretheoremstyle
和\declaretheorem
(并且,碰巧,与memoir
我正在使用的类)时也有效。
我如何调用thmtools
包的\declaretheoremstyle
和\declaretheorem
(使用memoir
)以适应建议的答案 - 尤其是egreg的答案?
更新:如果要继续的类定理环境已经有注释(即来自类似\begin{example}[some text]
),那么似乎需要一种不同于上述和下面接受的答案的方法。其中一种方法显示在https://tex.stackexchange.com/a/702575/13492。
答案1
我认为你不需要如此复杂的框架:我只能想到继续举例。
\documentclass[12pt]{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{example}[theorem]{Example}
\newtheorem*{excont}{Example \continuation}
\newcommand{\continuation}{??}
\newenvironment{continueexample}[1]
{\renewcommand{\continuation}{\ref{#1}}\excont[continued]}
{\endexcont}
\begin{document}
\begin{theorem}% 1
Theorem 1.
\end{theorem}
\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}
\begin{theorem}% 3
Theorem 3.
\end{theorem}
\begin{theorem}%4
Theorem 4.
\end{theorem}
\begin{proposition}
A proposition.
\end{proposition}
\begin{continueexample}{ex:ex2}
Example \ref{ex:ex2}, continued.
\end{continueexample}
\begin{theorem}% 5
Theorem 5.
\end{theorem}
\end{document}
只需为您想要继续的示例提供\label
,并将其用作的参数continueexample
。
没有thmtools
什么不同,只要记住使用\protect\continuation
。
\documentclass[12pt]{article}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheoremstyle[
bodyfont=\upshape,
]{upshape}
\declaretheorem[
name=Theorem,
within=section,
]{theorem}
\declaretheorem[
name=Proposition,
sibling=theorem,
]{proposition}
\declaretheorem[
style=upshape,
name=Example,
sibling=theorem,
]{example}
\declaretheorem[
style=upshape,
name=Example \protect\continuation,
unnumbered,
]{excont}
\newcommand{\continuation}{??}
\newenvironment{continueexample}[1]
{\renewcommand{\continuation}{\ref{#1}}\excont[continued]}
{\endexcont}
\begin{document}
\begin{theorem}% 1
Theorem 1.
\end{theorem}
\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}
\begin{theorem}% 3
Theorem 3.
\end{theorem}
\begin{theorem}%4
Theorem 4.
\end{theorem}
\begin{proposition}
A proposition.
\end{proposition}
\begin{continueexample}{ex:ex2}
Example \ref{ex:ex2}, continued.
\end{continueexample}
\begin{theorem}% 5
Theorem 5.
\end{theorem}
\end{document}
答案2
基于https://tex.stackexchange.com/a/311985/36296您可以创建一个新环境,自动从标签中获取上一个示例编号,并在继续示例后重置它。这将
省去手动添加的麻烦
\tobecontinued
,\continue
\resume
适用于每个示例,而不仅仅是最后一个标有
\tobecontinued
% continue-thm.try
\documentclass[12pt]{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{example}[theorem]{Example}
\newcounter{savedthmcounter}
\newcounter{tobecontinuedthmcounter}
\makeatletter
\def\@extractthmnum#1.#2{#2}
\newcommand{\extractthmnum}[2]{% \extractthmnum{<cnt>}{<ref>}
\setcounter{#1}{0}% Default
\ifcsname r@#2\endcsname
\edef\@tempa{\csname r@#2\endcsname}% Extract complete reference
\edef\@tempa{\expandafter\@firstoftwo\@tempa}% Extract number
\setcounter{#1}{\expandafter\@extractthmnum\@tempa}% Strip number
\fi
}
\makeatother
\newenvironment{excont}[1][]{
\extractthmnum{tobecontinuedthmcounter}{#1}
\addtocounter{tobecontinuedthmcounter}{-1}
\setcounter{savedthmcounter}{\value{theorem}}
\setcounter{theorem}{\value{tobecontinuedthmcounter}}
\begin{example}[continued]
}{
\end{example}
\setcounter{theorem}{\value{savedthmcounter}}
}
\begin{document}
\begin{theorem}% 1
Theorem 1.
\end{theorem}
\begin{example}% 2
\label{ex:ex2}
An example.
\end{example}
\begin{theorem}% 3
Theorem 3.
\end{theorem}
\begin{theorem}%4
Theorem 4.
\end{theorem}
\begin{proposition}
A proposition.
\end{proposition}
\begin{excont}[ex:ex2]% 2 again
Example \ref{ex:ex2}, continued.
\end{excont}
\begin{theorem}% 5
Theorem 5.
\end{theorem}
\end{document}