amsthm宏包提供了定理类和证明类环境,但是并不是开箱即用的,这里记录一下相关的使用方式和配置。

定理类环境

基于amsthm包可以创造定理类环境,语法包括如下几类

1
2
3
4
5
6
\newtheorem{name}{text}                     % 独自使用计数器
\newtheorem{name}{text}[section-level] % 基于section层级设置计数器
\newtheorem{name}{text}[counter] % 基于计数器层级设置下一层的计数器
\newtheorem{name}[counter]{text} % 共享其它环境的计数器

\newtheorem*{name}{text} % 不使用计数器

其中

  • name:必选的定理类环境的标识符(名称)
  • text:必选的显示环境名称(引导词)
  • 可选项的位置和名称有不同含义:
    • counter 在前面:共享前者的计数器,例如前者为1.1,后者则为1.2;
    • counter 在后面:继承前者的计数器,例如前者为1.1,后者则为1.1.1;
    • section-level 在后面:编号计数器依赖于某个章节层次,例如section 1的编号从1.1开始。

下面的常用环境都可以基于定理环境创建:(按照字体风格进行了分类)

  • plain风格
    • 定理 theorem
    • 推论 corollary
    • 引理 lemma
    • 命题 proposition
  • definition风格
    • 定义 definition
    • 例子 example
    • 问题 problem
  • remark风格
    • 注记 remark(remark*)
    • 笔记 note(note*)

使用时例如

1
2
3
\begin{theorem}
...
\end{theorem}

或者可以加上额外名称,会在引导词后加上括号显示

1
2
3
\begin{theorem}[xxx]
...
\end{theorem}

关于下面三个写法有必要辨析一下

1
2
3
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}

三者的区别为:

  • 对于theorem,根据当前section创建子编号;
  • 对于corollary,根据最近一次的theorem创建子编号,例如theorem 1.1之后的corollary采用编号1.1.1;
  • 对于lemma,与theorem共享计数器,例如theorem 1.1之后的lemma则采用编号1.2。

可以使用 \theoremstyle{style} 命令修改定理环境的样式,内置样式有三种:

  • plain(默认样式):引导词是正体,内容是斜体,通常用于定理/推论/引理/命题等
  • definition:引导词和内容都是正体,通常用于定义/条件/示例/问题等
  • remark:引导词是斜体,内容是正体,通常用于remark/note/断言/结论等

注意只有remark的引导词不会加粗显示。

完整的定义语法如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section] % 定理,基于section计数器
\newtheorem{corollary}{Corollary}[theorem] % 推论,继承定理的计数器(定理1.1,推论1.1.1)
\newtheorem{lemma}[theorem]{Lemma} % 引理,共享定理的计数器
\newtheorem{proposition}[theorem]{Proposition} % 命题,共享定理的计数器

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section] % 定义,基于section计数器
\newtheorem{example}{Example}[section] % 示例,基于section计数器
\newtheorem{problem}{Problem}[section] % 问题,基于section计数器

\theoremstyle{remark}
\newtheorem{remark}{Remark}[section] % remark,基于section计数器
\newtheorem{note}{Note}[section] % note,基于section计数器
\newtheorem*{remark*}{Remark} % remark*,无编号
\newtheorem*{note*}{Note} % note*,无编号

我们还可以使用thmtools宏包更简单直观地实现上述定理的设置,与上面几乎等价的一组配置命令如下 (与上文不完全相等,这里进行了简化,直接将推论和命题等视作一类,共享定理的计数器)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\usepackage{thmtools}

\declaretheorem[style=plain, numbered=yes, name=Theorem, numberwithin=section]{theorem}
\declaretheorem[style=plain, name=Corollary, sibling=theorem]{corollary}
\declaretheorem[style=plain, name=Lemma, sibling=theorem]{lemma}
\declaretheorem[style=plain, name=Proposition, sibling=theorem]{proposition}

\declaretheorem[style=definition, numbered=yes, name=Definition, numberwithin=section]{definition}
\declaretheorem[style=definition, name=Example, numberwithin=section]{example}
\declaretheorem[style=definition, name=Problem, numberwithin=section]{problem}

\declaretheorem[style=remark, numbered=yes, name=Remark, numberwithin=section]{remark}
\declaretheorem[style=remark, name=Note, numberwithin=section]{note}
\declaretheorem[style=remark, name=Remark, numbered=no]{remark*}
\declaretheorem[style=remark, name=Note, numbered=no]{note*}

补充:在定理类环境中如何直接使用列表环境,会导致第一项直接在首行的名称之后出现,与列表后续项的缩进不一致,看着很奇怪,可以通过在第一项之前加上\noindent实现。

证明类环境

amsthm也提供了用于写证明/解答的proof环境,不含有编号,默认样式包括:引导词Proof为斜体,内容是正体,结尾会自动添加证毕的方框符号。 可以直接使用,并不需要手动定义

1
2
3
\begin{proof}
...
\end{proof}

在默认情况下,proof环境使用斜体的proof作为默认引导词。

通过修改\proofname可以替换默认引导词,例如可以将默认引导词改为加粗的正体 proof

1
\renewcommand*{\proofname}{\normalfont\bfseries Proof}

由于ctex默认会将\proofname修改为中文的证明,这里改回来

1
2
3
% proof是默认存在的证明环境
% proofname默认是斜体英文proof,但是会被ctex修改为中文的证明,这里改回来
\renewcommand{\proofname}{\normalfont\bfseries Proof}

proof环境支持可选参数,可选参数会替换默认的引导词,例如

1
2
3
\begin{proof}[\normalfont\bfseries Solution]
...
\end{proof}

可以用来强调是某个定理/命题的证明,尤其在定理和证明分离时,例如

1
2
3
\begin{proof}[\normalfont\bfseries Proof of Theorem~\ref{thm:1}]
...
\end{proof}

可以简单地通过修改默认引导词定义一个与证明环境类似的解答环境。

1
\newenvironment{solution}{\begin{proof}[\textbf{Solution}]}{\end{proof}}

对于以不带编号公式结尾的证明,默认情况下证毕符号会另起一行,不太美观,可以使用\qedhere命令将证毕符号放在公式行的末尾,例如

1
2
3
4
5
6
\begin{proof}
For simplicity, we use
\[
E=mc^2 \qedhere
\]
\end{proof}

对于带编号的公式,则不建议使用\qedhere命令,因为编号和证毕符号的排版可能异常,不够美观。 对于多行公式最好也不要使用,因为证毕符号出现的位置可能不符合期望。

注:这里并没有对证明的引导词 Proof 采用缩进,可以加入\indent实现。