公式环境


公式包为美国数学学会数学包
\usepackage{amsmath}
默认的公式排版是公式居中,公式编号右对齐。公式环境是equation。
\begin{equation}
f(x)=\exp(x)
\end{equation}
\begin{equation} f(x)=\exp(x) \end{equation} 可以通过设置类的选项改变默认设置
\documentclass[12pt,fleqn]{article}  %公式左对齐
\setlength{\mathindent}{0pt}  %公式左对齐时设置公式缩进
\documentclass[12pt,leqno]{article}  %公式编号左边对齐,公式居中	
不编号的公式有两种写法,latex中环境名后加*一般是不编号的,包括table和figure都是如此
\begin{equation*}
f(x)=\exp(x)
\end{equation*}
\[
f(x)=\exp(x)
\]
\begin{equation*} f(x)=\exp(x) \end{equation*} \[ f(x)=\exp(x) \] 内置函数名不不多,可以用下面的语句自定义函数名,然后就可以类似默认函数使用
\DeclareMathOperator{\sgn}{sgn}  %sgn不是默认函数
但是并不推荐这种方法,更推荐下面的形式
\[
\text{sgn}(x)  \mathrm{sgn}(x)  {\rm sng}(x)
\]
\[ \text{sgn}(x) \mathrm{sgn}(x) {\rm sng}(x) \] 从这个例子可以看出,在公式里,多少空格都不会显示,需要空格是可以使用反斜杠+空格,或者\hspace{距离}
align环境,可以写多行公式且每个公式都编号,在align环境内使用&对齐。多行公式都不编号,align后面加星号就可以,不再举例。
\begin{align}
f(x)&=a_0+a_1x\\
g(x)&=\exp(x)
\end{align}
\begin{align} f(x)&=a_0+a_1x\\ g(x)&=\exp(x) \end{align} aligned环境可以在equation环境中套用,多行公式只有一个编号
\begin{equation}
\begin{aligned}
f(x)&=\sin x\\
g(x)&=\cos x+\tan x
\end{aligned}
\end{equation}
\begin{equation} \begin{aligned} f(x)&=\sin x\\ g(x)&=\cos x+\tan x \end{aligned} \end{equation} subequations环境是子公式且编号,注意是复数。
\begin{subequations}
\begin{equation}
f(x)=ax^2
\end{equation}
\begin{equation}\label{a}
g(x)=
\end{equation}
\end{subequations}
subequations环境是子公式且编号,公式对齐,则在subequations环境里套用align环境
\begin{subequations}
\begin{align}
f(x)&=ax^2\label{sub-1}\\
g(x)&=\label{sub-2}
\end{align}
\end{subequations}
这个例子还做了一个链接,注意label必须放在换行符前。
引用时用eqref自动加括号,否则只有编号

默认公式编号不带小节号,使用下面的语句自动添加小节号
\numberwithin{equation}{section}