Skip to main content

LaTeX 指南

本文为 LaTeX 使用指南,仅说明语法规则,不包含格式与排版建议。

参考资料

简介

LaTeX\LaTeX 是一种基于 TeX\TeX 的排版系统,用于编写包含数学公式的文档。

KaTeX\KaTeX 是一个在浏览器中运行的 JavaScript 数学公式渲染库,可以在网页上渲染使用 LaTeX\LaTeX 语法编写的数学公式。

推荐两个我常用的 LaTeX 排版网站 Overleaf在线 LaTeX 公式编辑器

公式类型

行内公式

行内公式(Inline Math)是嵌入在文本中的公式,其两侧分别用 单美元符号$)标记。

$...$

行间公式

行间公式(Math Blocks)是独立成行并居中的公式,其前后分别用 双美元符号$$)标记。

$$
...
$$
tip

行内公式的“大小”(如分数的大小、巨运算符上下标的位置)通常比行间公式小。可以使用 \displaystyle\textstyle 切换两种类型。

运算符号

基础

名称演示代码
加号+++
减号--
乘号×\times\times
点乘\cdot\cdot
除号÷\div\div
等号===\eq
不等号\ne\ne\neq
约等号\approx\approx
大于号>>>\gt
小于号<<<\lt
大于等于\geq\ge\geq
小于等于\leq\le\leq
正负号±\pm\pm\plusmn
无穷\infty\infty
根号x\sqrt{x}xy\sqrt[y]{x}\sqrt{x}\sqrt[y]{x}
分数ab\tfrac{a}{b}\frac{a}{b}
上取整\lceil\rceil\lceil\rceil
下取整\lfloor\rfloor\lfloor\rfloor
大括号{\{}\}\lbrace\{\rbrace\}

逻辑

名称演示代码
\land\land
\lor\lor
¬\lnot\lnot
推出    \implies\Rightarrow\implies\Rightarrow
反推    \impliedby\Leftarrow\impliedby\Leftarrow
等价    \iff\Leftrightarrow\iff\Leftrightarrow
因为\because\because
所以\therefore\therefore

巨运算符

求和

\sum_{i=1}^{n}a_i
http://localhost:3000
i=1nai\sum_{i=1}^{n}a_i

求积

\prod_{i=1}^{n}a_i
http://localhost:3000
i=1nai\prod_{i=1}^{n}a_i

积分

\int_{a}^{b}f(x)\mathrm{d}x
http://localhost:3000
abf(x)dx\int_{a}^{b}f(x)\mathrm{d}x

极限

\lim_{x\to\infty}f(x)
http://localhost:3000
limxf(x)\lim_{x\to\infty}f(x)

多行公式

递等式

\begin{aligned}
f(x) &= a \\
&= b \\
&= c
\end{aligned}
http://localhost:3000
f(x)=a=b=c\begin{aligned} f(x) &= a \\ &= b \\ &= c \end{aligned}

分段函数

f(x)=
\begin{cases}
a & x>0 \\
b & x=0 \\
c & x<0
\end{cases}
http://localhost:3000
f(x)={ax>0bx=0cx<0f(x)= \begin{cases} a & x>0 \\ b & x=0 \\ c & x<0 \end{cases}

线性方程组

\begin{cases}
a_1x+b_1y+c_1z=d_1 \\
a_2x+b_2y+c_2z=d_2 \\
a_3x+b_3y+c_3z=d_3
\end{cases}
http://localhost:3000
{a1x+b1y+c1z=d1a2x+b2y+c2z=d2a3x+b3y+c3z=d3\begin{cases} a_1x+b_1y+c_1z=d_1 \\ a_2x+b_2y+c_2z=d_2 \\ a_3x+b_3y+c_3z=d_3 \end{cases}

多行公式

\begin{array}{l}
\cos\pi=1 \\
\sin^2a+\cos^2a=1 \\
\sin2a=2\sin a\cos a
\end{array}
http://localhost:3000
cosπ=1sin2a+cos2a=1sin2a=2sinacosa\begin{array}{l} \cos\pi=1 \\ \sin^2a+\cos^2a=1 \\ \sin2a=2\sin a\cos a \end{array}
tip

通过调整 \begin{array} 后面的参数设置对齐方式:

{l} 表示左对齐;{c} 表示居中对齐;{r} 表示右对齐。

矩阵

\begin{bmatrix}
1 & 0 & \dots & 0 \\
0 & 1 & \dots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \dots & 1
\end{bmatrix}
http://localhost:3000
[100010001]\begin{bmatrix} 1 & 0 & \dots & 0 \\ 0 & 1 & \dots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \dots & 1 \end{bmatrix}

更多功能

边框

\boxed{a^2+b^2=c^2}
http://localhost:3000
a2+b2=c2\boxed{a^2+b^2=c^2}

颜色

{\color{White}\colorbox{Red}{FBI WARNING}}
http://localhost:3000
FBI WARNING{\color{White}\colorbox{Red}{FBI WARNING}}

字体

正体

g\approx 9.8\mathrm{m/s^2}
http://localhost:3000
g9.8m/s2g\approx 9.8\mathrm{m/s^2}

黑板粗体

x\in\mathbb{R}
http://localhost:3000
xRx\in\mathbb{R}

自定义运算符

\operatorname{lca}(6,8)=24
http://localhost:3000
lca(6,8)=24\operatorname{lca}(6,8)=24

编号

\tag{1}(a+b)^2=a^2+2ab+b^2
http://localhost:3000
(a+b)2=a2+2ab+b2(1)\tag{1}(a+b)^2=a^2+2ab+b^2