在
LaTeX
\LaTeX
LATEX 中输入定理需要 amsthm
宏包,但需要注意的是,并不是使用了该宏包之后就可以直接使用 theorem 环境。还需要通过 newtheorem
来指定定理的名称,最简单的示例如下:
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
然后就可以在文中使用
\begin{theorem}
This is a theorem.
\end{theorem}
\newtheorem命令的基本使用
使用\newtheorem
命令来定义新的定理环境,创建自定义的定理、引理、推论等结构,并为它们提供适当的编号和样式。
使用说明:
\newtheorem{环境名称}[编号层次]{显示名称}[计数器名称]
- 环境名称: 你希望创建的定理环境的名称。
- 编号层次: 可选参数。它指定了该定理环境的编号是否应该与其他定理环境共享相同的计数器。如果你想要一个新的计数器用于该环境,请提供一个新的名称。如果你希望共享现有的计数器(例如,定理和引理共享相同的计数器),则提供现有计数器的名称。
- 显示名称: 用于在输出中显示该定理环境的名称。
- 计数器名称: 可选参数。它指定了用于对该定理环境进行编号的计数器的名称。如果省略此参数,将使用默认的计数器。
示例:
\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{CustomTheorem}
\begin{document}
\section{Introduction}
\begin{thm}
This is a theorem.
\end{thm}
\section{Problem}
\begin{thm}
This is a theorem.
\end{thm}
\end{document}
可以得到如下连续编号的名为CustomTheorem的定理:
如果将上述代码中的 \newtheorem{thm}{CustomTheorem}
改为 \newtheorem{thm}{CustomTheorem}[section]
,则得到的是如下在每节重新编号的定理:
关于证明 proof
在使用了 amsthm
宏包之后,即可直接使用 \proof
环境,而无需像 theorem 那样用类似 \newproof 这样的命令先定义。
在某些模板中(如elsarticle.cls),之所以能使用 \newproof 命令更改环境名称是因为模板自己额外定义了该命令。其实一般情况下也无需单独定义,直接使用即可。
如在前述代码中加入
\begin{proof}
This is the proof.
\end{proof}
即可得到
这里能够看到,默认情况下,proof
环境的标题名是 “Proof”。
如果想要根据需要将其修改为其他语言或自定义的标题,可以使用 \renewcommand
命令来修改 proof
环境中的标题名。如:
\documentclass{article}
\usepackage{amsthm}
\renewcommand\proofname{CustomProof}
\begin{document}
\begin{proof}
This is the proof.
\end{proof}
\end{document}
如果想要进一步修改Proof的显示效果,则需要重新定义环境,比如MDPI的模板就做了相关设置,这里不做介绍,一般直接用模板即可。之后遇到实际需求再补上。
如果有的时候想要指定证明是面向哪个定理,也可以自定义当前proof的名称,也同样可以使用label+ref链接到响应定理。如:
\begin{thm}[Fundamental Theorem of Calculus]\label{Thm of Cal}
$$\int_{a}^{b} f(x)\,dx = F(b) - F(a).$$
\end{thm}
\begin{proof}[Proof of Theorem \ref{Thm of Cal}]
Please look for information on your own.
\end{proof}
所得结果如下。可以看到定理的名称仍然是导言区自定义的CustomTheorem,只不过是加了个括号。
如果不想使用默认的proof环境,那像下面定义引理、推论环境一样定义证明环境也是可以的。
\newtheorem{proof}{Proof}[section]
关于引理、推论等
不要被 \newtheorem 中的 theorem 所迷惑,实际上,引理、推论等也一样是通过 \newtheorem 来定义的。
对于如下代码
\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{CustomTheorem}[section]
\newtheorem{definition}[thm]{CustomDef} % 定义
\newtheorem{lemma}[thm]{CustomLemma} % 引理
\newtheorem{corollary}[thm]{CustomCor} % 推论
\newtheorem{example}[thm]{CustomEx} % 例
\newtheorem{proposition}[thm]{CustomPro} % 命题
%-------------------------------
\begin{document}
\section{Introduction}
\begin{thm}
This is a theorem.
\end{thm}
\begin{proof}[CustomProof]
This is the proof.
\end{proof}
\begin{definition}
This is a definition.
\end{definition}
%-------------------------------
\section{Problem}
\begin{thm}
This is a theorem.
\end{thm}
\begin{proof}
This is the proof.
\end{proof}
\begin{definition}
This is a definition.
\end{definition}
\end{document}
以 \newtheorem{definition}[thm]{CustomDef}
为例,这里的 {definition}
即是正文中的环境名,[thm]
则是意为继续着前面定义的 thm 环境继续编号,而 {CustomDef}
则是在pdf中显示的名称。
这里如果不写[thm]
,那么这个环境就是独立编号。比如写成
\newtheorem{definition}{CustomDef}[section] % 定义
那么显示效果就为
关于正体斜体
在上面的示例中发现,定理默认的样式是名称为正体加粗,内容为斜体,而证明默认的样式的名称斜体,内容为正体。
如果想要更改定理的样式的话(其实纯属吃饱了撑的),可以通过如下方式设置
\theoremstyle{plain} % 定义定理环境的样式,可选项包括"plain"、"definition"和"remark"
不同样式含义如下:
plain
:默认样式。definition
:标题为正体加粗,内容为正体。remark
:和默认证明样式一样,名称斜体,内容为正体。
比如对于如下设置:
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{thm}{CustomTheorem}[section]
\theoremstyle{plain}
\newtheorem{definition}[thm]{CustomDef} % 定义
\theoremstyle{remark}
\newtheorem{lemma}[thm]{CustomLemma} % 引理
得到的结果就会是
如果想要修改证明的样式,那可能需要重新定义环境,这里就不多介绍了。
一个较完整的案例
\documentclass{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{thm}{CustomTheorem}[section]
\renewcommand\proofname{MyProof}
\theoremstyle{plain}
\newtheorem{definition}[thm]{CustomDef} % 定义
\theoremstyle{remark}
\newtheorem{lemma}[thm]{CustomLemma} % 引理
\newtheorem{corollary}[thm]{CustomCor} % 推论
\newtheorem{example}[thm]{CustomEx} % 例
\newtheorem{proposition}[thm]{CustomPro} % 命题
%-----------------------------------------
\begin{document}
\section{Introduction}
\begin{thm}
This is a theorem.
\end{thm}
\begin{proof}[CustomProof]
This is the proof named CustomProof.
\end{proof}
\begin{definition}
This is a definition.
\end{definition}
\begin{lemma}
This is a lemma.
\end{lemma}
%-----------------------------------------
\section{Problem}
\begin{thm}
This is a theorem.
\end{thm}
\begin{proof}
This is the proof.
\end{proof}
\begin{definition}
This is a definition.
\end{definition}
\begin{thm}[Fundamental Theorem of Calculus]\label{Thm of Cal}
$$\int_{a}^{b} f(x)\,dx = F(b) - F(a).$$
\end{thm}
\begin{proof}[Proof of Theorem \ref{Thm of Cal}]
Please look for information on your own.
\end{proof}
\end{document}
显示效果为
精细控制
更多精细控制需要加载ntheorem
宏包,具体用法等之后用到再查。
可参考:https://blog.csdn.net/robert_chen1988/article/details/61204853