Latex书写多行公式常用的四大环境

前言

最近在为了美赛学习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} \]

posted @ 2022-01-21 17:27  Frodo1124  阅读(2006)  评论(0编辑  收藏  举报