前言
最近在為了美賽學習latex,這里記錄一下latex書寫多行公式常用的四大環境
宏包准備
\usepackage{amsmath}
\usepackage{amssymb}
gather環境
gather環境對齊方式是整體中間對齊
%多行公式--帶編號
\begin{gather}
a + b +c = b + a \\
1+2 = 2 + 1
\end{gather}
\[%多行公式--帶編號 \begin{gather} a + b +c = b + a \\ 1+2 = 2 + 1 \end{gather} \]
%多行公式--不帶編號1
\begin{gather*}
a + b = b + a \\
1+2 = 2 + 1
\end{gather*}
\[%多行公式--不帶編號1 \begin{gather*} a + b = b + a \\ 1+2 = 2 + 1 \end{gather*} \]
%多行公式--帶編號2 \notag 阻止編號
\begin{gather}
a + b = b + a \notag \\
1+2 = 2 + 1 \notag
\end{gather}
\[%多行公式--帶編號2 \notag 阻止編號 \begin{gather} a + b = b + a \notag \\ 1+2 = 2 + 1 \notag \end{gather} \]
align環境
按&號對齊,自己指定對齊方式
% 按&號對齊,--帶編號
\begin{align}
a+b &= b+a \\
1+2 &= 2+1
\end{align}
\[% 按&號對齊,--帶編號 \begin{align} a+b &= b+a \\ 1+2 &= 2+1 \end{align} \]
split環境
split環境當一個公式需要多行排版時,對齊方式也是按&對齊
%一個公式的多行排版--帶編號
\begin{equation}
\begin{split}
\cos 2x &= \cos^2 x - \sin^2x \\
&=2\cos^2x-1
\end{split}
\end{equation}
\[%一個公式的多行排版--帶編號 \begin{equation} \begin{split} \cos 2x &= \cos^2 x - \sin^2x \\ &=2\cos^2x-1 \end{split} \end{equation} \]
cases環境及分段函數
cases環境用於分段函數或者有左大括號的數學公式
%case環境, text{}在數學模式中處理中文-帶編號
\begin{equation}
D(x)=\begin{cases}
1, & \text{如果} x \in \mathbb{Q};\\
0, & \text{如果} x \in \mathbb{R}\setminus\mathbb{Q}
\end{cases}
\end{equation}
\[%case環境, text{}在數學模式中處理中文-帶編號 \begin{equation} D(x)=\begin{cases} 1, & \text{如果} x \in \mathbb{Q};\\ 0, & \text{如果} x \in \mathbb{R}\setminus\mathbb{Q} \end{cases} \end{equation} \]