LaTeX學習-day10
教程鏈接:B站
使用環境:
- 系統:Windows 10
- TeX 系統:TeX Live (官網下載)(清華源)
- IDE:Tex Studio
多行數學公式
1. 代碼:
%導言區
\documentclass{ctexart}
\usepackage{amssymb}
\usepackage{amsmath}
%正文區
\begin{document}
LaTeX中多行數學公式
% gather 和 gather* 環境(可以使用\\換行)
% 帶編號
\begin{gather}
a+b=b+a \\
ab=ba
\end{gather}
% 不帶編號
\begin{gather*}
3+5=5+3=8 \\
3 \times 5 = 5 \times 3
\end{gather*}
% 在\\前使用\notag 阻止編號
\begin{gather}
3^2 + 4^2 = 5^2 \notag \\
5^2 + 12^2 = 13^2 \notag \\
a^2 + b^2 = c^2
\end{gather}
%align和align* 環境(用 & 進行對齊)
%允許公式按等號或其他關係符對齊,在關係符前加 &表示對齊;
%允許排列多列對齊公式,列與列之間使用& 分隔;
% 帶編號
\begin{align}
x & = t + \cos t + 1 \\
y & = 2\cos t
\end{align}
% 不帶編號
\begin{align*}
x & = t & x &= \cos t & x &= t \\
y & = 2t & y &= \sin(t+1) & y &= t
\end{align*}
%split環境(對齊採用split環境的方式,編號在中間)
\begin{equation}
\begin{split}
\cos 2x &= \cos^2 x - \sin^2 x \\
&= 2\cos^2 x - 1
\end{split}
\end{equation}
%cases環境
%每行公式中使用 & 分隔爲兩部分,
%通常表示值和後面的條件
\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}
\end{document}