一、如何自定义函数
引入所需要的库
%默认equation环境无法满足要求,用amsmath包
\usepackage{amsmath}
引入想要自定义的函数
%自定义函数
\DeclareMathOperator{\sgn}{sgn}
定义好sgn函数后可以对其进行使用
%sgn不是默认含数,定义后如同默认使用
\[
\sgn(x)
\]
输出结果
当然也可以不定义自定义函数而直接创建自己想要的函数
%也可以用text设定函数为正体,不需要定义sgn
\[
f(x)=\text{sgn}(x)
\]
%或者使用rm,也不需要定义sgn
\[
f(x)={\rm sgn}(x)
\]
输出结果
二、如何灵活设置尾标
上篇博文中已经知道如何设置编号,在这里将其进行丰富和多元化设置
如何使用equation不添加编号
\begin{equation} %默认添加编号
f(x) = a_1 x^2
\end{equation}
\begin{equation*} %不添加编号
f_{2}(x)=\ln(x)
\end{equation*}
输出结果
当然也可以像上篇所说的一样进行简写,也可以实现不添加编号
进行多行公式的定义和编号设置。其中&定义对齐位置
%多行公式且分别编号,&定义对齐位置
\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*}
输出结果
多行公式一个编号
%多行公式一个编号
\begin{equation}
\begin{aligned}
f(x)&=g(x)\\
&=a\sin x+b\cos x
\end{aligned}
\end{equation}
输出结果
这里以 = 为对齐方式
关于子公式编号设置
%子公式编号
\begin{subequations}
\begin{equation}
f(x)=ax^2
\end{equation}
\begin{equation}
g(x)=
\end{equation}
\end{subequations}
%子公式编号且对齐
\begin{subequations}
\begin{align}
f(x)=ax^2 \label{sub-1}
g(x)&=\label{sub-2} %关于=进行对齐
\end{align}
\end{subequations}
输出结果
如何再公式中引用文字
%在公式里引用文字
\begin{equation}
f(x)=\cos(x)\hspace{1cm}\text{every thing}
\end{equation}
输出结果