LaTeX数学公式的矩阵、多行公式
目录
- 矩阵公式
- 数学公式的多行公式
- 矩阵公式
% 导言区
\documentclass{article}
\usepackage{ctex}
\usepackage{amsmath} %矩阵宏包
% 创建新命令,自定义省略号类型
\newcommand{\adots}{\mathinner{\mkern2mu%
\raisebox{0.1em}{.}\mkern2mu\raisebox{0.4em}{.}%
\mkern2mu\raisebox{0.7em}{.}\mkern1mu}}
% 正文区
\begin{document}
%矩阵环境,用&分割列,用\\分割行
\[
\begin{matrix}
0 & 1 \\
1 & 0
\end{matrix} \qquad
%pmatrix环境
\begin{pmatrix} %小括号
0 & 1 \\
1 & 0
\end{pmatrix} \qquad
%bmatrix
\begin{bmatrix} %中括号
0 & 1 \\
1 & 0
\end{bmatrix} \qquad
%Bmatrix
\begin{Bmatrix} %大括号
0 & 1 \\
1 & 0
\end{Bmatrix} \qquad
%vmatrix
\begin{vmatrix} %单竖线
0 & 1 \\
1 & 0
\end{vmatrix} \qquad
%Vmatrix
\begin{Vmatrix} %双竖线
0 & 1 \\
1 & 0
\end{Vmatrix}
\]
% 可以使用上下标
\[
A = \begin{pmatrix}
a_{11}^2 & a_{12}^2 & a_{13}^2 \\
0 & a_{22} & a_{23} \\
0 & 0 & a_{33}
\end{pmatrix}
\]
% 常用省略号:\dots、\vdots、\ddots
% 自定义\adots 输出自定义省略号
\[
A = \begin{bmatrix}
a_{11} & \dots & a_{1n} \\
\adots & \ddots & \vdots \\
0 & & a_{nn}
\end{bmatrix}_{n \times n}
\]
%分块矩阵(矩阵嵌套)
\[
\begin{pmatrix}
\begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix}
& \text{\Large 0} \\
\text{\Large 0} &
\begin{matrix}
1 & 0 \\ 0 & -1 \end{matrix}
\end{pmatrix}
\]
% 三角矩阵
\[
\begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
& a_{22} & \cdots & a_{2n} \\
& & \ddots & \vdots \\
\multicolumn{2}{c}{\raisebox{1.3ex}[0pt]{\Huge 0}}
& & a_{nn}
\end{pmatrix}
\]
% 行内小矩阵(smallmatrix)环境
复数 $ z = (x,y)$ 也可用矩阵
\begin{math}
\left( % 加左括号
\begin{smallmatrix}
x & -y \\ y & x
\end{smallmatrix}
\right) %
\end{math} %加右括号
% array 环境(类似于表格tabular)
\[
\begin{array}{r|r}
\frac 12 & 0 \\
\hline
0 & - \frac abc \\
\end{array}
\]
% 用array 环境构造复杂矩阵
\[
% @{<内容>}——添加任意内容,不占表项计数
% 此处添加一个负值空白,表示向左移-5pt的距离
\begin{array}{c@{\hspace{-5pt}}l}
% 第1行,第1列
\left(
\begin{array}{ccc|ccc}
a & \cdots & a & b & \cdots & b \\
& \ddots & \vdots & \vdots & \adots \\
& & a & b \\ \hline
& & & c & \cdots & c \\
& & & \vdots & & \vdots \\
\multicolumn{3}{c|}{\raisebox{2ex}[0pt]{\Huge 0}}
& c & \cdots & c
\end{array}
\right)
&
% 第1行第2列
\begin{array}{l}
% \left.仅表示与\right}配对,什么都不输出
\left.\rule{0mm}{7mm}\right\}p \\
\\
\left.\rule{0mm}{7mm}\right\}q
\end{array}
\\ [-5pt]
% 第2行第1列
\begin{array}{cc}
\underbrace{\rule{17mm}{0mm}}_m &
\underbrace{\rule{17mm}{0mm}}_m
\end{array}
& % 第2行第2列
\end{array}
\]
\end{document}
2. 数学公式的多行公式
% 导言区
\documentclass{article}
\usepackage{ctex}
\usepackage{amsmath}
\usepackage{amssymb}
% 正文区
\begin{document}
% 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*}
% 在\\前使用\notage 阻止编号
\begin{gather}
3^2 + 4^2 = 5^2 \notag \\
5^2 + 12^2 = 13^2 \notag \\
a + b = b + a
\end{gather}
% align 和align* 环境(用&进行对齐)
%带编号
\begin{align}
x &= t + \cos t + 1 \\
y &= 2 \sin t
\end{align}
% 不带编号
\begin{align*}
x &= t & x &= \cos t & x &= t \\
y &= 2t & y &= \sin (t+1) & y &= \sin t
\end{align*}
% solit 环境(对齐采用align环境的方式,编号在中间)
\begin{equation}
\begin{split}
\cos 2x &= \cos^2 x - \sin^2 x \\
&= 2\cos^2 x -1
\end{split}
\end{equation}
% cass环境 (类似分段函数)
% 每行公式中使用 & 分隔为两部分,
% 通常表示值和后面的条件
\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}