LaTeX
定理环境
通过“定理”我们可以指任何一种带标签的表述,希望将其从其他文本中分隔开,并且在旁边显示序号。这种方法通常用于数学定理,但也可以用于任何内容。LaTeX 提供了一个命令,允许你轻松定义任何类似定理的表述。
基本定理
首先,确保启用了 amsthm
包:
\usepackage{amsthm}
最简单的定义方式如下:
\newtheorem{name}{Printed output}
将其放在导言部分。第一个参数是你将用来引用它的名称,第二个参数是当你使用它时,LaTeX 将打印的输出。例如:
\newtheorem{mydef}{Definition}
这将定义 mydef
环境;如果你这样使用它:
\begin{mydef}
Here is a new definition
\end{mydef}
它将显示为这样:
Definition 1. Here is a new definition
并且有换行将其与文本其余部分分开。
定理计数器
通常,计数器是由章节确定的,例如,“定理 2.3”指的是文档中第 2 章的第 3 个定理。在这种情况下,可以在导言部分按如下方式指定定理:
\newtheorem{theorem}{Theorem}[section]
并在需要时使用它:
\begin{theorem}
If $A$ is positive definite symmetric,
\end{theorem}
或者,使用通用的 "name" 来输出 "Printed output",加上 numberby
:
\newtheorem{name}{Printed output}[numberby]
其中 numberby
是章节级别的名称(如章节、子章节等),在此级别进行编号。
默认情况下,每个定理使用自己的计数器。然而,对于类似类型的定理(例如定理、引理和推论)来说,它们通常共享一个计数器。在这种情况下,可以将后续定理定义为:
\newtheorem{name}[counter]{Printed output}
其中 counter
是要使用的计数器的名称。通常,这将是主定理的名称。
\newtheorem
命令最多可以有一个可选参数。
无编号定理环境
你也可以创建一个没有编号的定理环境,使用 \newtheorem*
命令:
\newtheorem*{mydef}{Definition}
这将定义 mydef
环境,生成没有编号的定义。此方法需要 amsthm
包。
证明环境
proof
环境[1] 用于添加定理的证明。基本用法如下:
\begin{proof}
Here is my proof
\end{proof}
它将在文本的开头添加斜体的 "Proof",并在末尾添加一个白色方块(Q.E.D. 符号,也叫墓碑符号)。如果你使用的语言不是英语,只需使用 babel
包并传入正确的参数,"Proof" 将自动翻译成目标语言;不过,在源代码中,环境的名称始终保持为 proof
。
如果你想手动为证明命名,可以在方括号中包括名称:
\begin{proof}[Proof of important theorem]
Here is my important proof
\end{proof}
如果证明的最后一行是显示数学公式,那么 Q.E.D. 符号将出现在后续的空白行中。若要将 Q.E.D. 符号放置在最后一行的末尾,可以使用 \qedhere
命令:
\begin{proof}
Here is my proof:
\[
a^2 + b^2 = c^2 \qedhere
\]
\end{proof}
上述方法不适用于已弃用的 eqnarray*
环境,使用 align*
代替。
要使用自定义的 Q.E.D. 符号,可以重新定义 \qedsymbol
命令。要完全隐藏 Q.E.D. 符号,可以将其重新定义为空:
\renewcommand{\qedsymbol}{}
定理样式
可以使用 \theoremstyle
命令[1]在文档的导言部分更改由 \newtheorem
定义的环境的输出样式:
\theoremstyle{stylename}
参数是你想使用的样式。所有后续定义的定理将使用此样式。以下是预定义样式的列表:
stylename | 描述 | 外观 |
---|---|---|
plain | 用于定理、引理、命题等(默认) | Theorem 1. Theorem text. |
definition | 用于定义和示例 | Definition 2. Definition text. |
remark | 用于备注和注释 | Remark 3. Remark text. |
自定义样式
要定义自定义样式,使用 \newtheoremstyle
命令[1]:
\newtheoremstyle{stylename}% name of the style to be used
{spaceabove}% measure of space to leave above the theorem. E.g.: 3pt
{spacebelow}% measure of space to leave below the theorem. E.g.: 3pt
{bodyfont}% name of font to use in the body of the theorem
{indent}% measure of space to indent
{headfont}% name of head font
{headpunctuation}% punctuation between head and body
{headspace}% space after theorem head; " " = normal interword space
{headspec}% Manually specify head
(任何留空的参数将假定为默认值)。例如,使用 headspec
:
\thmname{#1}\thmnumber{ #2}:\thmnote{ #3}
这将看起来像这样:
Definition 2: Topology
对于以下内容:
\begin{definition}[Topology]...
(note
参数,即此处的 "Topology",始终是可选的,但默认不会出现,除非你像上面那样在头部规范中指定它)。
冲突问题
定理环境与其他环境(例如 wrapfigure
)存在冲突。解决方法是重新定义定理环境,例如以下方式:
% Fix latex
\def\smallskip{\vskip\smallskipamount}
\def\medskip{\vskip\medskipamount}
\def\bigskip{\vskip\bigskipamount}
% 手动定义定理
\newcounter{thm}[section]
\renewcommand{\thethm}{\thesection.\arabic{thm}}
\def\claim#1{\par\medskip\noindent\refstepcounter{thm}\hbox{\bf \arabic{chapter}.\arabic{section}.\arabic{thm}. #1.}
\it\ %\ignorespaces
}
\def\endclaim{
\par\medskip}
\newenvironment{thm}{\claim}{\endclaim}
在这种情况下,定理看起来像这样:
\begin{thm}{Claim}\label{lyt-prob}
Let it be.
Then you know.
\end{thm}
注意事项
-
需要
amsthm
包
外部链接