参考

在 CMD 中输入下面的命令可以打开《一份不太简短的latex介绍》

1
texdoc lshort-zh

访问 lshort | github 可以获取这篇文章的 LaTex 源代码。

参考视频: latex中文教程-15集从入门到精通包含各种latex操作

视频由西北农林科技大学信息工程学院耿楠老师于2016年录制

LaTeX环境配置

  • 安装 Texlive

    使用 tex --version 命令查看环境变量是否配置成功, 如果没有则在环境变量中添加 D:\texlive\2021\bin\win32

  • 安装 TeXstudio (可选)

    Option -> Configure TeXstudio -> Build -> Default Compiler 中设置 TeXstudio 默认编译方式为 Xelatex

  • 安装 VSCode + LaTex Workshop (可选, 推荐)

LaTeX源文件的基本结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
%导言区
\documentclass{article} %选择文本模式, 可选项有article/book/report/letter

\title{Title Of My Article} %设置文章标题
\author{xiaophai} %设置文章作者
\date{\today} %设置文章日期

%正文区
\begin{document}
\maketitle %插入标题

Hello World! %撰写正文

\end{document}

LaTeX处理中文的方法

  • 设置-构建 中默认编译器设置为XeLaTeX

  • 设置-编辑器 默认字体编码 UTF-8

  • 引入ctex宏包

    引入ctex宏包后才能显示中文, 否则中文字符不显示, 但编译不报错

1
2
3
4
5
6
7
8
\documentclass{article}
\usepackage{ctex} %引入ctex宏包

\begin{document}

你好, \LaTeX

\end{document}
  • 下面两种用法效果是一样的
1
\documentclass{ctexart}
1
2
\documentclass{article}
\usepackage{ctex}
  • cmd中输入下面的命令可以打开<CTeX宏集手册>
1
texdoc ctex

LaTeX的字体字号设置

  • 英文字体的设置命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%字体命令,作用于命令参数--{}中的内容
\textrm{Roman Family} %罗马字体
\textsf{Sans Serif Family} %无衬线字体
\texttt{Typewriter Family} %打字机字体

%字体声明,作用于后续的文本
\rmfamily Roman Family
\sffamily Sans Serif Family
\ttfamily Typewriter Family

%也可以使用大括号对字体进行分组,从而限定字体声明的作用范围
{\rmfamily Roman Family}
{\sffamily Sans Serif Family}
{\ttfamily Typewriter Family}
1
2
3
4
5
6
7
8
9
10
11
%字体命令
\textup{Upright Shape} %直立
\textit{Italic Shape} %斜体
\textsl{Slanted Shape} %伪斜体
\textsc{Small Caps Shape} %小型大写

%字体声明
{\upshape Upright Shape}
{\itshape Italic Shape}
{\slshape Slanted Shape}
{\scshape Small Capes Shape}
1
2
3
4
5
6
7
8
9
%中文字体的设置
{\songti 宋体} %宋体
{\heiti 黑体} %黑体
{\fangsong 仿宋} %仿宋
{\kaishu 楷书} %楷书

\textbf{粗体} %粗体
\textit{斜体} %斜体
{\bfseries 加粗}
  • 英文字号的设置命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{\tiny Hello}
{\scriptsize Hello}
{\footnotesize Hello}
{\small Hello}
{\normalsize Hello}
{\large Hello}
{\Large Hello}
{\LARGE Hello}
{\huge Hello}
{\Huge Hello}

%这些字体的大小是相对于normalsize的字号而言的
%而normalsize的大小是由文档类的参数控制的
%文档类的参数是一个可选参数,可以在方括号中添加
%normalsize只能设置10/11/12pt
\documentclass[10pt]{article}
\documentclass[11pt]{article}
\documentclass[12pt]{article}

tinyHelloscriptsizeHellofootnotesizeHellosmallHellonormalsizeHellodefaultHellolargeHelloLargeHelloLARGEHellohugeHelloHugeHello\begin{array}{rl} \tiny tiny & \tiny Hello\\ \scriptsize scriptsize & \scriptsize Hello\\ \footnotesize footnotesize & \footnotesize Hello\\ \small small & \small Hello\\ \normalsize normalsize & \normalsize Hello\\ \textcolor{blue}{default} & \textcolor{blue}{Hello}\\ \large large & \large Hello\\ \Large Large & \Large Hello\\ \LARGE LARGE & \LARGE Hello\\ \huge huge & \huge Hello\\ \Huge Huge & \Huge Hello \end{array}

  • 中文字号的设置命令
1
2
%中文字号设置命令
\zihao{5} 你好!
  • 自定义字体命令

当需要复杂且常用的字体命令时可以在导言区自定义命令

1
2
3
4
%导言区
\newcommand{\newfont}{\textbf{\textsf{Fancy Text}}}
%正文区
\newfont
  • pt对字号
字号 初号 小初 一号 小一 二号 小二 三号
大小 42pt 36pt 26pt 24pt 22pt 18pt 16pt
字号 小三 四号 小四 五号 小五 六号 小六
大小 15pt 14pt 12pt 10pt 9pt 7.5pt 6.5pt

LaTeX文档的基本结构

  • 标题的使用
1
2
3
4
5
6
7
8
9
10
11
12
%导言区
\documentclass{ctexart}
%正文区
\begin{document}
\section{实验方法}
\section{实验结果}
\subsection{数据获取}
\subsubsection{实验条件}
\subsubsection{实验过程}
\subsection{结果分析}
\section{结论}
\end{document}

image-20220207234726959

  • 空行和"\\"的区别
    • "\\"只是换行, 行首不会缩进
    • 空行是开启新的段落, 行首有缩进
1
2
3
4
5
6
7
8
9
%导言区
\documentclass{ctexart}
%正文区
\begin{document}
多年以后,奥雷连诺上校站在行刑队面前,准会想起父亲带他去参观冰块的那个遥远的下午。
\\当时,马孔多是个二十户人家的村庄,一座座土房都盖在河岸上,河水清澈,沿着遍布石头的河床流去,河里的石头光滑、洁白,活象史前的巨蛋。

这块天地还是新开辟的,许多东西都叫不出名字,不得不用手指指点点。每年三月,衣衫褴楼的吉卜赛人都要在村边搭起帐篷,在笛鼓的喧嚣声中,向马孔多的居 民介绍科学家的最新发明。
\end{document}

image-20220207222314075

  • 自定义标题格式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
\ctexset{
section={
%format用于设置章节标题全局格式,作用域为标题和编号
%字号为小三,字体为黑体,左对齐
%+号表示在原有格式下附加格式命令
format+ = \zihao{-3} \heiti \raggedright,
%name用于设置章节编号前后的词语
%前、后词语用英文状态下,分开
%如果没有前或后词语可以不填
name = {,、},
%number用于设置章节编号数字输出格式
%输出section编号为中文
number = \chinese{section},
%beforeskip用于设置章节标题前的垂直间距
%ex为当前字号下字母x的高度
%基础高度为1.0ex,可以伸展到1.2ex,也可以收缩到0.8ex
beforeskip = 1.0ex plus 0.2ex minus .2ex,
%afterskip用于设置章节标题后的垂直间距
afterskip = 1.0ex plus 0.2ex minus .2ex,
%aftername用于控制编号和标题之间的格式
%\hspace用于增加水平间距
aftername = \hspace{0pt}
},
subsection={
format+ = \zihao{4} \kaishu \raggedright,
%仅输出subsection编号且为中文
number = \chinese{subsection},
name = {(,)},
beforeskip = 1.0ex plus 0.2ex minus .2ex,
afterskip = 1.0ex plus 0.2ex minus .2ex,
aftername = \hspace{0pt}
},
subsubsection={
%设置对齐方式为居中对齐
format+ = \zihao{-4} \fangsong \centering,
%仅输出subsubsection编号,格式为阿拉伯数字,打字机字体
number = \ttfamily\arabic{subsubsection},
name = {,.},
beforeskip = 1.0ex plus 0.2ex minus .2ex,
afterskip = 1.0ex plus 0.2ex minus .2ex,
aftername = \hspace{0pt}
}
}

image-20220207233649953

LaTeX中的特殊字符

  • 空白符号
    • 空行分段, 多个空行等同一个空行
    • 自动缩进, 绝对不能使用空格代替
    • 英文中多个空格处理为一个空格, 中文中空格被忽略
    • 汉字与其它字符的间距会自动由XeLaTeX处理
    • 禁止使用中文全角空格
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
a\quad b   %1em(当前字体中M的宽度)
a\qquad b %2em
a\, b %约1/6个em
a\thinspace b %约1/6个em
a\enspace b %约1/2个em
a\ b %输出一个空格
a~b %一个硬空格

% 1pc = 12pt = 4.218mm
a\kern 1pc b
a\kern -1em b
a\hskip 1em b
a\hspace{35pt}b

%占位宽度
a\hphantom{xyz}b

%弹性空白
a\hfill b %可以用于让一行中的一部分右对齐

image-20220208010116391

  • 控制符输出
1
\# \$ \% \{ \} \~{} \_{} \^{} \& \textbackslash

image-20220208010645086

  • 排版符号
1
\S \P \dag \ddag \copyright \pounds

image-20220208011344650

  • Latex标识符
1
\TeX{} \LaTeX{} \LaTeXe{}

image-20220208011555476

  • 引号
1
2
3
4
`  %左单引号--数字键1左边的键
' %右单引号
`` %左双引号
'' %右双引号

image-20220208012102426

  • 连字符
1
- -- ---

image-20220208012405425

  • 注音符号
1
\=o \'o \v{o} \`o 

image-20220208013501390

LaTeX中的插图

  • 基础用法
1
2
3
4
5
6
7
8
%导言区
\usepackage{graphicx}

%可以使用下面命令指定图片的存储目录,可以指定多个
\graphicspath{{figures/},{pics/}}

%语 法
\includegraphics[<选项>]{<图片名>} %支持格式:EPS,PDF,PNG,JPEG,BMP
  • 可选参数
1
2
3
4
5
6
7
8
9
\includegraphics[scale=0.3]{}  %比例缩放
\includegraphics[height=2cm]{} %固定高度
\includegraphics[width=2cm]{} %固定宽度

\includegraphics[height=0.1\textheight]{} %版型高度的倍数
\includegraphics[width=0.2\textwidth]{} %版型宽度的倍数

%指定旋转角度,不同参数之间用逗号进行分割
\includegraphics[angle=-45,width=0.2\textwidth]{}
  • 多张插图的排版
1
2
%使用subfigure命令需要引用subfigure宏包
\usepackage{subfigure}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\begin{figure}[htbp]
\centering

\subfigure[标题1]{
\includegraphics[width=0.4\textwidth]{fig-1}
}
&
\subfigure[标题2]{
\includegraphics[width=0.4\textwidth]{fig-2}
}
\\
\subfigure[标题3]{
\includegraphics[width=0.4\textwidth]{fig-3}
}
&
\subfigure[标题4]{
\includegraphics[width=0.4\textwidth]{fig-4}
}
\caption{大标题}
\end{figure}
  • Latex双栏排版
1
2
3
4
5
6
\usepackage{multicol}  %使用宏包

%环境命令
\begin{multicols}{2}

\end{multicols}
  • 双栏排版中使用插入通栏图片
1
2
3
4
5
6
%普通的figure环境加上*号
\begin{figure*}[htbp]
\centering
\includegraphics[width=\textwidth]{...}
\caption{...}
\end{figure*}

效果如下

image-20220219225041433

  • 双栏插图

Latex的双栏环境是不支持浮动体的, 直接使用figure环境会导致图片丢失.

1
2
3
4
5
6
7
8
%借助float宏包的[H]选项
\usepackage{float}
%注意这样插入的图片位置是固定的,需要手动调整其位置
\begin{figure}[H]\label{...}
\centering
\includegraphics[width=0.5\textwidth]{...}
\caption{...}
\end{figure}

image-20220219230239753

LaTeX中的表格和列表

表格在线生成工具

Latex表格的绘制语法较为复杂, 建议使用表格生成工具

  • 表格基础绘制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
% 用\\表示换行
% 用&表示不同列
% l-本列左对齐
% c-本列居中对齐
% r-本列右对齐
% p{<宽度>}-本列宽度固定,文本超出宽度能够自动换行

\begin{tabular}{l||c|c|c|r} %使用两个||产生双竖线
\hline
姓名 & 语文 & 数学 & 英语 & 备注 \\
\hline \hline %使用两个\hline产生双横线
张三 & 87 & 100 & 93 & 优秀 \\
\hline
李四 & 75 & 64 & 52 & 补考 \\
\hline
王五 & 80 & 82 & 78 & \\
\hline
\end{tabular}

image-20220208191620640

  • 三线表的绘制
1
2
3
4
5
6
7
8
9
10
11
%导言区
\usepackage{booktabs} %需要加载宏包{booktabs}

%绘制三线表
\begin{tabular}{ccccc}
\toprule %添加表格头部粗线
x & 0 & 1 & 2 & 3 \\
\midrule %添加表格中横线
Pr & 1/8 & 3/8 & 3/8 & 1/8 \\
\bottomrule %添加表格底部粗线
\end{tabular}

image-20220208193707291

  • 符号说明

长表格分页排版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
\begin{longtable}[h]{lcl}
\caption{主要变量符号及意义}\\
% Table header
\toprule[1.5pt]
\makebox[0.03\textwidth][l]{序号} & \makebox[0.1\textwidth][c]{符号} & \makebox[0.7\textwidth][c]{意义}\\
\midrule[1pt]
% 以下两个命令选择一个
\endfirsthead % 表头只在第一页出现
\endhead % 表头每一页都出现

% Table foot
\bottomrule[1.5pt]
% 以下两个命令选择一个
\endlastfoot % 表尾只在最后一个出现
\endfoot % 表尾每一页都出现

% data begins here
1 & $x_1$ & 说明1 \\
2 & $x_2$ & 说明2 \\
3 & $x_3$ & 说明3 \\
4 & $x_4$ & 说明4 \\
5 & $x_5$ & 说明5 \\
6 & $x_6$ & 说明6 \\
7 & $x_7$ & 说明7 \\
8 & $x_8$ & 说明8 \\
9 & $x_9$ & 说明9
\label{tab:symbol1}
\end{longtable}

使用\endfirstheader\endfoot效果

\endfirstheader&\endfoot

使用\endheader\endfoot效果

\endheader&\endfoot
  • Latex中的列表

LaTeX 中常见的列表环境有 enumerate、itemize 和 description。这三种列表环境的主要区别是列表项标签的不同:

1.enumerate 是有序的列表

1
2
3
4
5
\begin{enumerate}
\item This is the first item
\item This is the second item
\item This is the third item
\end{enumerate}
1
2
3
4
5
6
7
\usepackage{enumitem}
%给编号加上括号(需要enumitem宏包)
\begin{enumerate}[label={(\arabic*)}]
...
\end{enumerate}
%其它参数设置
%\arabic*(阿拉伯数字)、\roman*(小写罗马数字)、\Roman*(大写罗马数字)、\Alph*(大写字母编号)、\alph*(小写字母编号)

img

2.itemize 以圆点作为标签

1
2
3
4
5
\begin{itemize}
\item This is the first item
\item This is the second item
\item This is the third item
\end{itemize}

img

3.description 是解说列表,可以指定标签

1
2
3
4
5
6
%\usepackage{pifont}
\begin{description}
\item[\ding{47}] This is the first item
\item[\ding{47}] This is the second item
\item[\ding{47}] This is the third item
\end{description}

img

LaTeX中的浮动体

浮动体是为了排版更加紧密, 有的图片直接放文字下面会另起一页, 浮动体就避免了这个问题.

  • 插图浮动体环境
1
2
3
4
5
6
7
8
9
\LaTeX{}的吉祥物,小狮子见图\ref{fig-lion}
%使用\ref{}命令可以引用设置过label的图片
\begin{figure}[htbp]
\centering
\includegraphics[scale=0.3]{lion}
\caption{\LaTeX{}的吉祥物---小狮子} %设置图片标题
\label{fig-lion} %设置label
\end{figure}

image-20220208195741724

  • 表格浮动体环境
1
2
3
4
5
6
7
8
9
10
\begin{table}[!htbp]
\centering %居中排版
\begin{tabular}{ccccc}
\toprule %添加表格头部粗线
x & 0 & 1 & 2 & 3 \\
\midrule %添加表格中横线
Pr & 1/8 & 3/8 & 3/8 & 1/8 \\
\bottomrule %添加表格底部粗线
\end{tabular}
\end{table}

<允许位置>参数(默认tbp)

h 代表此处(here), 代码所在的上下文位置
t 代表页顶(top), 代码所在的页面或者之后页面的顶部
b 代表页底(bottom), 代码所在的页面或者之后页面的底部
p 代表独立一页(page), 浮动页面
! 表示忽略美观因素,尽可能按照参数指定的方式来处理表格浮动位置。

LaTeX数学公式初步

公式在线生成工具

TexStudio行内公式快捷键Ctrl+Shift+M

TexStudio行间公式快捷键Ctrl+Shift+N

  • 行内公式
1
2
3
4
% 行内公式用$...$
$x^2+y^2 = 1$
% 或者使用\(...\)
$x^2+y^2 = 1$

x2+y2=1x^2+y^2 = 1

  • 行间公式
1
2
3
4
5
6
7
8
9
10
11
12
%行间公式用$$...$$
$$
\sin^2(x)+\cos^2(x)=1
$$
%也可以使用\[...\]
\[
\sin^2(x)+\cos^2(x)=1
\]
%还可以使用displaymath环境
\begin{displaymath}
\sin^2(x)+\cos^2(x)=1
\end{displyamath}

sin2(x)+cos2(x)=1\sin^2(x)+\cos^2(x)=1

  • equation环境
1
2
3
4
5
6
7
8
9
10
11
12
%使用equation环境可对公式实现自动编号
%在equation环境中可以使用\label{}命令对公式贴标签
%在任意位置通过\ref{}命令引用标签
\begin{equation}
\sin^2(x)+\cos^2(x)=1 \label{eq:identity1}
\end{equation}

%当不需要对公式进行编号时,可以使用equation*环境对公式进行排版
%此时依然可以使用\label{}和\ref{}命令,此时交叉引用的编号是小结编号
\begin{equation*}
\sin^2(x)+\cos^2(x)=1 \label{eq:identity2}
\end{equation*}
\begin{equation} \sin^2(x)+\cos^2(x)=1 \label{eq:identity1} \end{equation}
  • 上下标
1
$a_1,a_{22},a^3,a^{44},a_{5}^{6}$

a1,a22,a3,a44,a56a_1,a_{22},a^3,a^{44},a_{5}^{6}

  • 希腊字母
A\Alpha α\alpha alpha N\Nu ν\nu nu
B\Beta β\beta beta Ξ\Xi ξ\xi xi
Γ\Gamma γ\gamma gamma O\Omicron ο\omicron omicron
Δ\Delta δ\delta delta Π\Pi π\pi pi
E\Epsilon ϵ\epsilon epsilon P\Rho ρ\rho rho
Z\Zeta ζ\zeta zeta Σ\Sigma σ\sigma sigma
H\Eta η\eta eta T\Tau τ\tau tau
Θ\Theta θ\theta theta Υ\Upsilon υ\upsilon upsilon
I\Iota ι\iota iota Φ\Phi ϕ\phi phi
K\Kappa κ\kappa kappa X\Chi χ\chi chi
Λ\Lambda λ\lambda lambda Ψ\Psi ψ\psi psi
M\Mu μ\mu mu Ω\Omega ω\omega omega
  • variant

ϵθπρσϕεϑϖϱςφvarepsilonvarthetavarpivarrhovarsigmavarphi\begin{array}{} \epsilon & \theta & \pi & \rho & \sigma & \phi \\ \varepsilon & \vartheta & \varpi & \varrho & \varsigma & \varphi\\ \text{varepsilon} & \text{vartheta} & \text{varpi} & \text{varrho} & \text{varsigma} & \text{varphi} \end{array}

  • Letter-like符号
1
\imath \jmath \ell \Re

ıȷ\imath \quad \jmath \quad \ell \quad \Re

  • 数学函数
1
\log,\ln,\sin,\cos,\tan,\arcsin,\arccos,\arctan,\exp

log,ln,sin,cos,tan,arcsin,arccos,arctan,exp,\log,\ln,\sin,\cos,\tan,\arcsin,\arccos,\arctan,\exp,\cdots

  • 根式和分式
1
\sqrt{x}, \sqrt[3]{x}

x,x3\sqrt{x}, \sqrt[3]{x}

1
3/4, \frac{3}{4}

3/4,343/4, \frac{3}{4}

  • 范数符号&绝对值符号
1
2
范数符号: \Vert 或者 \|
绝对值符号: \lvert 或者 \rvert 或者 \vert

aa\Vert a \| \quad \lvert a \rvert

  • 长竖线
1
\big|  \Big| \bigg| \Bigg|

x01x01x01x01x\big|_0^1 \qquad x\Big|_0^1 \qquad x\bigg|_0^1 \qquad x\Bigg|_0^1

  • 关系符号
1
\neq \leq \geq \equiv 

\neq \qquad \leq \qquad \geq \qquad \equiv

1
\in \notin \ni(或者\owns) \not\ni(或者\not\owns) \ll \gg 

∌\in \qquad \notin \qquad \owns \qquad \not\owns \qquad \ll \qquad \gg

1
\subset \supset \subseteq \supseteq \cup \cap

\subset \qquad \supset \qquad \subseteq \qquad \supseteq \qquad \cup \qquad \cap

1
\propto \sim \approx \cong \perp

\propto \qquad \sim \qquad \approx \qquad \cong \qquad \perp

1
\because \therefore \forall \exists \nexists

\because \qquad \therefore \qquad \forall \qquad \exists \qquad \nexists

  • 向下向上取整
1
\lfloor \rfloor \lceil \rceil

\lfloor \quad \rfloor \quad \lceil \quad \rceil

  • 运算符号
1
\sum \prod \bigcup \bigcap

\sum \qquad \prod \qquad \bigcup \qquad \bigcap

1
\int \iint \iiint \oint 

\int \qquad \iint \qquad \iiint \qquad \oint

1
\partial \nabla \pm \mp \div \circ \bullet \star \dagger

±÷\partial \qquad \nabla \qquad \pm \qquad \mp \qquad \div \qquad \circ \qquad \bullet \qquad \star \qquad \dagger

1
\lim \varliminf \varlimsup \limsup \liminf 

limlimlimlim suplim inf\lim \qquad \varliminf \qquad \varlimsup \qquad \limsup \qquad \liminf

1
\max \min \sup \inf

maxminsupinf\max \qquad \min \qquad \sup \qquad \inf

1
\bar{x} \tilde{x} \hat{x} \dot{x} \ddot{x}

x~x^x˙x¨xˉ\tilde{x} \qquad \hat{x} \qquad \dot{x} \qquad \ddot{x} \qquad \bar{x}

  • rlap 和 llap
1
2
3
4
5
6
\begin{array}{ll}
rlap: & \xrightarrow{text} right \\
& \rlap{$\xrightarrow{text}$} right\\
llap: & left \xleftarrow{text}\\
& left \llap{$\xleftarrow{text}$}\\
\end{array}

rlap:textrighttextrightllap:lefttextlefttext\begin{array}{ll} rlap: & \xrightarrow{text} right \\ & \rlap{$\xrightarrow{text}$} right\\ llap: & left \xleftarrow{text}\\ & left \llap{$\xleftarrow{text}$}\\ \end{array}

1
\overline{xyz} \underline{xyz} \qquad \overbrace{xyz}^{over} \underbrace{xyz}_{under}

xyzxyzxyzoverxyzunder\overline{xyz} \qquad \underline{xyz} \qquad \overbrace{xyz}^{over} \qquad \underbrace{xyz}_{under}

1
a+\rlap{ $ \overbrace{\phantom{b+c+d}}^{m} $}b+\underbrace{c+d+e}_{n}+f

a+ b+c+dmb+c+d+en+fa+\rlap{ $ \overbrace{\phantom{b+c+d}}^{m} $}b+\underbrace{c+d+e}_{n}+f

1
\widehat{xyz} \widetilde{xyz} \overleftarrow{xyz} \overrightarrow{xyz} \underrightarrow{xyz} \underleftarrow{xyz}

xyz^xyz~xyzxyzxyzxyz\widehat{xyz} \qquad \widetilde{xyz} \qquad \overleftarrow{xyz} \qquad \overrightarrow{xyz} \qquad \underrightarrow{xyz} \qquad \underleftarrow{xyz}

1
2
3
4
5
6
x \xrightarrow[below]{above} y
x \xRightarrow[below]{above} y
x \xhookrightarrow[below]{above} y
x \xrightarrow[below]{above} y
x \xrightharpoonup[below]{above} y
x \xrightharpoonup[below]{above} y

xbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyx \xrightarrow[below]{above} y \quad x \xRightarrow[below]{above} y \quad x \xhookrightarrow[below]{above} y \quad x \xrightarrow[below]{above} y \quad x \xrightharpoonup[below]{above} y \quad x \xrightharpoonup[below]{above} y

1
2
3
4
5
6
x \xleftarrow[below]{above} y
x \xLeftarrow[below]{above} y
x \xhookleftarrow[below]{above} y
x \xleftarrow[below]{above} y
x \xleftharpoonup[below]{above} y
x \xleftharpoonup[below]{above} y

xbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyx \xleftarrow[below]{above} y \quad x \xLeftarrow[below]{above} y \quad x \xhookleftarrow[below]{above} y \quad x \xleftarrow[below]{above} y \quad x \xleftharpoonup[below]{above} y \quad x \xleftharpoonup[below]{above} y

1
2
3
4
5
x \xmapsto[below]{above} y
x \xleftrightarrow[below]{above} y
x \xLeftrightarrow[below]{above} y
x \xrightleftharpoons[below]{above} y
x \xleftrightharpoons[below]{above} y

xbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyxbelowaboveyx \xmapsto[below]{above} y \quad x \xleftrightarrow[below]{above} y \quad x \xLeftrightarrow[below]{above} y \quad x \xrightleftharpoons[below]{above} y \quad x \xleftrightharpoons[below]{above} y

1
\square \blacksquare

\square \qquad \blacksquare

1
\frown \smile \overgroup{xyz} \undergroup{xyz}

xyzxyz\frown \qquad \smile \qquad \overgroup{xyz} \qquad \undergroup{xyz}

1
\sharp \flat \natural \flat\kern-1.4pt\flat

\sharp \quad \flat \quad \natural \quad \flat\kern-1.4pt\flat

1
2
\otimes \oplus \ominus \odot
\boxplus \boxminus \boxtimes \boxdot

\oplus \qquad \ominus \qquad \otimes \qquad \odot \\ \boxplus \qquad \boxminus \qquad \boxtimes \qquad \boxdot

1
\heartsuit \spadesuit \lozenge \clubsuit

\heartsuit \qquad \spadesuit \qquad \lozenge \qquad \clubsuit

  • overset和underset
1
\overset{note}{\rm normal} \overset{?}{=}

normalnote=?=def\overset{note}{\rm normal} \qquad \overset{?}{=} \qquad \overset{def}{=}

1
\underset{note}{\rm normal} \underset{\alpha,\beta}{\arg \min}

normalnoteargminα,β\underset{note}{\rm normal} \qquad \underset{\alpha,\beta}{\arg \min}

  • 大括号

{[(01x2dx)]}\left.\left\{\left[\left(\int_0^1 x^2 dx \right)\right]\right\}\right|

  • 组合数
1
\tbinom{n}{k} {n \choose k} C_n^k

(nk)(nk)(nk)Cnk\binom{n}{k} \quad \tbinom{n}{k} \quad {n \choose k} \quad C_n^k

  • atop
1
{u \atop v} {a \below b}

uv{u \atop v}

  • 删除线
1
\cancel{xyz} \bcancel{xyz} \xcancel{xyz} \sout{xyz}

xyzxyzxyzxyz\cancel{xyz} \quad \bcancel{xyz} \quad \xcancel{xyz} \quad \sout{xyz}

  • 长横线
1
2
\rule[raise-height]{length}{thickness}
X\rule[0.2em]{20em}{0.1em}X

XXX\rule[0.2em]{20em}{0.1em}X

  • 长空白
1
X\hspace{4cm}X

XXX\hspace{4cm}X

  • 数学符号加黑
1
2
%使用\boldsymbol{}
\alpha,\boldsymbol{\alpha}

α,α\alpha,\boldsymbol{\alpha}

1
2
3
%在是数学环境中比较推荐的是添加bm宏包
\usepackage{bm}
%使用\bm{}命令对数学符号进行加粗
  • 数学黑板粗体符号Blackboard Bold
1
2
\usepackage{amssymb} %黑板粗体需要amssymb宏包
\mathbb{R},\mathbb{Q}

R,Q\mathbb{R},\mathbb{Q}

  • 数学公式中的字体

数学公式默认字体中, 数字和中文为罗马体, 英文和希腊字母为意大利斜体

1
2
3
4
5
6
7
0默认字体:数字和中文为\mathrm{},英文和希腊字母为\mathit{}
1正粗体Boldface: \mathbf{...}
2意大利斜体Italic: \mathit{...}
3罗马正体Roma: \mathrm{...}
4德文哥特体Fraktur: \mathfrak{...} 李代数中常用
5花体Calligraphy: \mathcal{...}
6手写体Script: \mathscr{...} 线性变换的符号

0默认字体:123abcABCαβγ甲乙丙1正粗体:123abcABCαβγ甲乙丙2意大利斜体:123abcABCαβγ甲乙丙3罗马正体:123abcABCαβγ甲乙丙4德国哥特体:123abcABCαβγ甲乙丙5花体:123abcABCαβγ甲乙丙6手写体:123abcABCαβγ甲乙丙\begin{split} 0默认字体&:123abcABC\alpha\beta\gamma甲乙丙\\ 1正粗体&:\mathbf{123abcABC\alpha\beta\gamma甲乙丙}\\ 2意大利斜体&:\mathit{123abcABC\alpha\beta\gamma甲乙丙}\\ 3罗马正体&:\mathrm{123abcABC\alpha\beta\gamma甲乙丙}\\ 4德国哥特体&:\mathfrak{123abcABC\alpha\beta\gamma甲乙丙}\\ 5花体&:\mathcal{123abcABC\alpha\beta\gamma甲乙丙}\\ 6手写体&:\mathscr{123abcABC\alpha\beta\gamma甲乙丙} \end{split}

  • 给公式标色
1
2
3
4
5
6
%导言区
\usepackage{color}
%正文区
{未标色内容\color{<颜色>}标色内容} %作用于作用域之后所有的内容
\textcolor{<颜色>}{<公式/文本>}
\colorbox{<颜色>}{<$公式$/文本>} %注意colorbox的公式要用$...$框住

ex的泰勒展开式:ex=1+x+12x2++1n!xn+o(xn){\color{brown} e^x的泰勒展开式:}\quad \textcolor{green}{e^x}=\textcolor{red}{1} + \textcolor{blue}{x} +\colorbox{yellow}{$\frac{1}{2}x^2$} + \cdots + \colorbox{red}{$\frac{1}{n!}x^n$} + o(x^n)

可以给整个矩阵标色

[××××××××××××××××][××××××××××××××××]\textcolor{red}{ \begin{bmatrix} \times & \times & \times & \times\\ \times & \times & \times & \times\\ \times & \times & \times & \times\\ \times & \times & \times & \times \end{bmatrix} } \quad \colorbox{yellow}{$ \begin{bmatrix} \times & \times & \times & \times\\ \times & \times & \times & \times\\ \times & \times & \times & \times\\ \times & \times & \times & \times \end{bmatrix} $}

  • 可用颜色

  • 8种基本色

black red green blue white cyan magenta yellow
$$\colorbox{black}{\quad}$$ $$\colorbox{red}{\quad}$$ $$\colorbox{green}{\quad}$$ $$\colorbox{blue}{\quad}$$ $$\fbox{\colorbox{white}{\quad}}$$ $$\colorbox{cyan}{\quad}$$ $$\colorbox{magenta}{\quad}$$ $$\colorbox{yellow}{\quad}$$
  • xcolor额外补充的一些基本色(这些在markdown的数学语法中都可以使用)
1
2
%导言区
\usepackage[cmyk]{xcolor}
darkgray gray lightgray brown olive orange
$$\colorbox{darkgray}{\quad}$$ $$\colorbox{gray}{\quad}$$ $$\colorbox{lightgray}{\quad}$$ $$\colorbox{brown}{\quad}$$ $$\colorbox{olive}{\quad}$$ $$\colorbox{orange}{\quad}$$
lime purple teal violet pink gold
$$\colorbox{lime}{\quad}$$ $$\colorbox{purple}{\quad}$$ $$\colorbox{teal}{\quad}$$ $$\colorbox{violet}{\quad}$$ $$\colorbox{pink}{\quad}$$ $$\colorbox{gold}{\quad}$$
silver maroon teal fuchsia blueviolet skyblue
$$\colorbox{silver}{\quad}$$ $$\colorbox{maroon}{\quad}$$ $$\colorbox{teal}{\quad}$$ $$\colorbox{fuchsia}{\quad}$$ $$\colorbox{blueviolet}{\quad}$$ $$\colorbox{skyblue}{\quad}$$

常用 RGB 颜色对照表

  • 盒子

\colorbox{darkgray}{$\quad$}

1
\fbox{$公式$/文本}

等价无穷小: ex1+x,x0\fbox{等价无穷小: $e^x \sim 1 + x,\quad x \rightarrow 0$}

可以给矩阵画框

××××××××××××××××\fbox{$ \begin{matrix} \times & \times & \times & \times\\ \times & \times & \times & \times\\ \times & \times & \times & \times\\ \times & \times & \times & \times \end{matrix} $}

x00x00+x01x01x00+x10x00+x01+x10+x11x01+x11x10x10+x11x11\begin{array}{ccc} x_{00} & \fbox{$\begin{matrix} x_{00}+x_{01} \end{matrix}$} & x_{01}\\ \fbox{$\begin{matrix} x_{00}\\+\\x_{10} \end{matrix}$} & \fbox{$\begin{matrix} x_{00}+x_{01}\\+\\x_{10}+x_{11} \end{matrix}$} & \fbox{$\begin{matrix} x_{01}\\+\\x_{11} \end{matrix}$}\\ x_{10} & \fbox{$\begin{matrix} x_{10}+x_{11} \end{matrix}$} & x_{11}\\ \end{array}

  • 常用箭头
符号 公式 符号 公式
\leftarrow \leftarrow或\gets \rightarrow \rightarrow或\to
\nleftarrow \nleftarrow \nrightarrow \nrightarrow
\Leftarrow \Leftarrow \Rightarrow \Rightarrow
\nLeftarrow \nLeftarrow \nRightarrow \nRightarrow
\leftrightarrow \leftrightarrow \Leftrightarrow \Leftrightarrow
\nleftrightarrow \nleftrightarrow \nLeftrightarrow \nLeftrightarrow
\longleftarrow \longleftarrow \longrightarrow \longrightarrow
\Longleftarrow \Longleftarrow \Longrightarrow \Longrightarrow
\hookleftarrow \hookleftarrow \hookrightarrow \hookrightarrow
\leftharpoonup \leftharpoonup \rightharpoonup \rightharpoonup
\leftharpoondown \leftharpoondown \rightharpoondown \rightharpoondown
\leftrightharpoons \leftrightharpoons \rightleftharpoons \rightleftharpoons
\looparrowleft \looparrowleft \looparrowright \looparrowright
\twoheadleftarrow \twoheadleftarrow \twoheadrightarrow \twoheadleftarrow
\leftarrowtail \leftarrowtail \rightarrowtail \rightarrowtail
\leftleftarrows \leftleftarrows \rightrightarrows \rightrightarrows
\leftrightarrows \leftrightarrows \rightleftarrows \rightleftarrows
\upuparrows \upuparrows \downdownarrows \downdownarrows
\dashleftarrow \dashleftarrow \dashrightarrow \dashrightarrow
\curvearrowleft \curvearrowleft \curvearrowright \curvearrowright
\leftrightsquigarrow \leftrightsquigarrow \rightsquigarrow \rightsquigarrow
\longleftrightarrow \longleftrightarrow \Longleftrightarrow \Longleftrightarrow
\uparrow \uparrow \downarrow \downarrow
\Uparrow \Uparrow \Downarrow \Downarrow
\updownarrow \updownarrow \Updownarrow \Updownarrow
\nwarrow \nwarrow \nearrow \nearrow
\swarrow \swarrow \searrow \searrow
\Lsh \Lsh \Rsh \Rsh
\mapsto \mapsto \longmapsto \longmapsto
\multimap \multimap

LaTeX数学公式----矩阵

  • matrix环境
1
2
%使用matrix环境需要先引入amsmath宏包
\usepackage{amsmath}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
%使用matrix环境
$$
\begin{matrix} %无括号
0 & 1 \\
1 & 0
\end{matrix},
\begin{pmatrix} %小括号(...)
0 & 1 \\
1 & 0
\end{pmatrix},
\begin{bmatrix} %中括号[...]
0 & 1 \\
1 & 0
\end{bmatrix},
\begin{Bmatrix} %大括号{...}
0 & 1 \\
1 & 0
\end{Bmatrix},
\begin{vmatrix} %单竖线|...|
0 & 1 \\
1 & 0
\end{vmatrix},
\begin{Vmatrix} %双竖线||...||
0 & 1 \\
1 & 0
\end{Vmatrix}
$$

0110,(0110),[0110],{0110},0110,0110\begin{matrix} 0 & 1 \\ 1 & 0 \end{matrix}, \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, \begin{Bmatrix} 0 & 1 \\ 1 & 0 \end{Bmatrix}, \begin{vmatrix} 0 & 1 \\ 1 & 0 \end{vmatrix}, \begin{Vmatrix} 0 & 1 \\ 1 & 0 \end{Vmatrix}

  • 矩阵中的省略号
1
2
3
4
5
6
%省略号
\dots \cdots \vdots \ddots \iddots
%其中iddots需要mathdots宏包

%也可以使用\newcommand命令来定义一个反对角省略符号
\newcommand\iddots{\mathinner{ \kern1mu\raise1pt{.} \kern2mu\raise4pt{.} \kern2mu\raise7pt{\Rule{0pt}{7pt}{0pt}.} \kern1mu}}

\dots \qquad \cdots \qquad \vdots \qquad \ddots \qquad

\newcommand\iddots{\mathinner{\kern1mu\raise1pt{.} \kern2mu\raise4pt{.} \kern2mu\raise7pt{\Rule{0pt}{7pt}{0pt}.} \kern1mu}} \iddots
1
2
3
4
5
6
7
8
%使用hdotsfor{<列数>}产生跨列省略号
$$
\begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
\hdotsfor{4} \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{pmatrix}
$$

image-20220214115700543

  • 三角矩阵
1
2
3
4
5
6
7
8
9
$$
\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}
$$

image-20220214003015185

  • 行内小矩阵
1
2
3
4
5
6
%使用smallmatrix环境排版行内小矩阵
\left( %需要手动添加括号
\begin{smallmatrix}
x & -y \\ y & x
\end{smallmatrix}
\right)

例如矩阵(xyyx)\left( \begin{smallmatrix} x & -y \\ y & x \end{smallmatrix} \right)是排版在行内的

  • array环境

array环境可以对矩阵的元素进行居左|居中|居右的排版

1
2
3
4
5
6
7
$$
\begin{array}{c|c|c}
x & 0 & 1 \\
\hline
p(x) & \frac{1}{4} & \frac{3}{4}
\end{array}
$$

x01p(x)1434\begin{array}{c|c|c} x & 0 & 1 \\ \hline p(x) & \frac{1}{4} & \frac{3}{4} \end{array}

  • 使用 array 制作建议表格

半音阶口琴音阶图

1
2
3
4
5
6
7
\begin{array}{|c|cccccccccccccccc|}
\hline
Blow & C & E & G & C & C & E & G & C & C & E & G & C & C & E & G & C\\
\hline
Draw & D & F & A & B & D & F & A & B & D & F & A & B & D & F & A & B\\
\hline
\end{array}

BlowCEGCCEGCCEGCCEGCDrawDFABDFABDFABDFAB\begin{array}{|c|cccccccccccccccc|} \hline Blow & C & E & G & C & C & E & G & C & C & E & G & C & C & E & G & C\\ \hline Draw & D & F & A & B & D & F & A & B & D & F & A & B & D & F & A & B\\ \hline \end{array}

  • 测量 array 环境下 cell 的默认宽度
1
2
3
4
5
6
\begin{array}{|c|c|c|c|c|c|c|c|}
\rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} &
\rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{}
\end{array}
\\
\rule{11cm}{}

\begin{array}{|c|c|c|c|c|c|c|c|} \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} & \rule{1cm}{} \end{array} \\ \rule{11cm}{}

一个短线段为 1cm1cm,长线段为 11cm11cm,array 环境下 88 个短线段的长度等于 11cm11cm,计算出 (118)/8=0.375cm(11-8)/8=0.375cm,即 array 环境每个单元格的宽度为 0.375cm0.375cm

  • 使用array环境排版复杂矩阵
1
2
3
4
5
6
7
8
9
10
%第一行第一列: 大复合矩阵
\left(
\begin{array}{cc|cc}
a_{11} & a_{12} & b_{11} & b_{12}\\
a_{21} & a_{22} & b_{21} & b_{22}\\
\hline
& & c_{11} & c_{12}\\
& & c_{21} & c_{22}
\end{array}
\right)

(a11a12b11b12a21a22b21b22c11c12c21c22)%第一行第一列: 大复合矩阵 \left( \begin{array}{cc|cc} a_{11} & a_{12} & b_{11} & b_{12}\\ a_{21} & a_{22} & b_{21} & b_{22}\\ \hline & & c_{11} & c_{12}\\ & & c_{21} & c_{22} \end{array} \right)

1
2
3
4
5
%第一行第二列: 右侧大括号
\begin{array}{l}
\left. \rule{0mm}{7mm} \right\}p \\
\left. \rule{0mm}{7mm} \right\}q
\end{array}

}p}q%第一行第二列: 右侧大括号 \begin{array}{l} \left. \rule{0mm}{7mm} \right\}p \\ \left. \rule{0mm}{7mm} \right\}q \end{array}

1
2
3
4
5
%第二行第一列: 下侧大括号
\begin{array}{cc}
\underbrace{\rule{17mm}{0mm}}_m &
\underbrace{\rule{17mm}{0mm}}_m
\end{array}

mm%第二行第一列: 下侧大括号 \begin{array}{cc} \underbrace{\rule{17mm}{0mm}}_m & \underbrace{\rule{17mm}{0mm}}_m \end{array}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$$
\begin{array}{c@{\hspace{-5pt}}l}
%第一行第一列: 大复合矩阵
\left(
\begin{array}{cc|cc}
a_{11} & a_{12} & b_{11} & b_{12}\\
a_{21} & a_{22} & b_{21} & b_{22}\\
\hline
& & c_{11} & c_{12}\\
& & c_{21} & c_{22}
\end{array}
\right)
& %&符号连接行间元素
%第一行第二列: 右侧大括号
\begin{array}{l}
\left. \rule{0mm}{7mm} \right\}p \\
\left. \rule{0mm}{7mm} \right\}q
\end{array}
%第一行结束
\\
%第二行第一列: 下侧大括号
\begin{array}{cc}
\underbrace{\rule{17mm}{0mm}}_m &
\underbrace{\rule{17mm}{0mm}}_m
\end{array}
&
%第二行第二列: 空
\end{array}
$$

(a11a12b11b12a21a22b21b22c11c12c21c22)}p}qmm\begin{array}{cl} %第一行第一列: 大复合矩阵 \left( \begin{array}{cc|cc} a_{11} & a_{12} & b_{11} & b_{12}\\ a_{21} & a_{22} & b_{21} & b_{22}\\ \hline & & c_{11} & c_{12}\\ & & c_{21} & c_{22} \end{array} \right) & %&符号连接行间元素 %第一行第二列: 右侧大括号 \begin{array}{l} \left. \rule{0mm}{7mm} \right\}p \\ \left. \rule{0mm}{7mm} \right\}q \end{array} \\ %第一行结束 %第二行第一列: 下侧大括号 \begin{array}{cc} \underbrace{\rule{17mm}{0mm}}_m & \underbrace{\rule{17mm}{0mm}}_m \end{array} & %第二行第二列: 空 \end{array}

1
2
3
4
5
6
7
\begin{bmatrix}
0 & 1/3 & 0 & \cdots & 0 \\
2/3 & 0 & 1/3 & \cdots & 0 \\
0 & 2/3 & 0 & \ddots & 0 \\
\vdots & \vdots & \ddots & \ddots & 1/3 \\
0 & 0 & 0 & 2/3 & 0
\end{bmatrix}

[01/3002/301/3002/3001/30002/30]\begin{bmatrix} 0 & 1/3 & 0 & \cdots & 0 \\ 2/3 & 0 & 1/3 & \cdots & 0 \\ 0 & 2/3 & 0 & \ddots & 0 \\ \vdots & \vdots & \ddots & \ddots & 1/3 \\ 0 & 0 & 0 & 2/3 & 0 \end{bmatrix}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\begin{array}{cl}
&
\begin{matrix}
-1 & -2 & -3 & \cdots
\end{matrix}
\\
\begin{matrix}
-1 \\ -2 \\ -3 \\ \vdots
\end{matrix}
&
\begin{bmatrix}
0 & 1/3 & 0 & \cdots \\
2/3 & 0 & 1/3 & \cdots \\
0 & 2/3 & 0 & \ddots \\
\vdots & \vdots & \ddots & \ddots
\end{bmatrix}
\end{array}

123123[01/302/301/302/30]\begin{array}{cl} & \begin{matrix} -1 & -2 & -3 & \cdots \end{matrix} \\ \begin{matrix} -1 \\ -2 \\ -3 \\ \vdots \end{matrix} & \begin{bmatrix} 0 & 1/3 & 0 & \cdots \\ 2/3 & 0 & 1/3 & \cdots \\ 0 & 2/3 & 0 & \ddots \\ \vdots & \vdots & \ddots & \ddots \end{bmatrix} \end{array}

LaTeX数学公式的多行公式

1
2
\usepackage{amsmath}
\usepackage{amssymb} %数学花体符号需要amssymb宏包
  • gather和gather*环境实现多行公式排版

gather环境默认多行公式居中对其(markdown中使用该环境可以居中对其多行公式)

1
2
3
4
\begin{gather}
a + b = b + a \\
a \cdot b = b \cdot a \notag %\notag或者\nonumber命令抑制此行编号
\end{gather}

a+b=b+aab=ba\begin{gather} a + b = b + a \\ a \cdot b = b \cdot a \end{gather}

  • align和align*环境按指定位置对齐
    align和align* 按照 & 符号对内容进行右左右左右…交替对齐
1
2
3
4
\begin{align}
x &= t + \cos(t) + 1 \\
y &= 2\sin(t)
\end{align}

x=t+cos(t)+1y=2sin(t)\begin{align} x &= t + \cos(t) + 1 \\ y &= 2\sin(t) \end{align}

1
2
3
4
\begin{align*}
x &= t & x &= \cos(t) & x &= t \\
y &= 2t & y &= \sin(t+1) & y &= \sin(t)
\end{align*}

x=tx=cos(t)x=ty=2ty=sin(t+1)y=sin(t)\begin{align*} x &= t & x &= \cos(t) & x &= t \\ y &= 2t & y &= \sin(t+1) & y &= \sin(t) \end{align*}

上面 align* 实现的效果可以用 array 环境来实现

1
2
3
4
\begin{array}{rlrlrl}
x &= t & x &= \cos(t) & x &= t \\
y &= 2t & y &= \sin(t+1) & y &= \sin(t)
\end{array}

x=tx=cos(t)x=ty=2ty=sin(t+1)y=sin(t)\begin{array}{rlrlrl} x &= t & x &= \cos(t) & x &= t \\ y &= 2t & y &= \sin(t+1) & y &= \sin(t) \end{array}

  • 公式对齐 aligned 环境
1
2
3
4
5
\begin{aligned}
x |&= xyz\\
xy |&= xy\\
xyz |&= x
\end{aligned}

x=xyzxy=xyxyz=x\begin{aligned} x |&= xyz\\ xy |&= xy\\ xyz |&= x \end{aligned}

  • split环境实现一个公式的多行排版

split环境可以通过&符号来自定义公式的对齐

注意split环境本身不能单独使用, 需要放在equation环境中才能使用

注意不能放在$$...$$中, 会出问题.

1
2
3
4
5
6
\begin{equation}
\begin{split}
\cos 2x &= \cos^2 x - \sin^2 x \\
&= 2\cos^2 x -1
\end{split}
\end{equation}

cos2x=cos2xsin2x=2cos2x1\begin{split} \cos 2x &= \cos^2 x - \sin^2 x \\ &= 2\cos^2 x -1 \end{split}

注意 split 环境只能使用一个 & 符号进行对齐, 当尝试像 align 环境那样多列对齐时会报错

\begin{split} x &= t & x &= \cos(t) & x &= t \\ y &= 2t & y &= \sin(t+1) & y &= \sin(t) \end{split}
  • cases环境
1
2
3
4
5
6
7
\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}
%数学花体符号需要amssymb宏包

D(x)={1,如果xQ;0,如果xRQ.\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}

  • 插入数学定理/引理/证明
1
2
3
4
5
6
\usepackage{amsthm} % 如果要使用proof环境需要引入amsthm宏包
%其要放在\newtheorem命令的前面,否则会报错

% 使用下面命令定义定理/明题/定义等环境
\newtheorem{定理环境名}{标题}[主计数器]
%其中[主计数器]为可选参数,可以选择[chapter][section]等
1
2
3
4
5
\newtheorem{theorem}{定理}[section]
%定义了一个"theorem"环境,其标题是"定理",其跟随section计数
\begin{theorem}\label{...}
...
\end{theorem}
1
2
3
4
5
6
7
8
%proof环境
\begin{proof}[证明:]
...
\end{proof}
%其中[...]为可选项
%proof环境会在证明结束的时候自动打印"□"符号(\qedsymbol)
%如果想输入证毕,则需要进行\renewcommand
\renewcommand*{\qedsymbol}{[证毕]}
1
2
3
4
5
%使用ntheorem宏包
\usepackage{ntheorem}
%amsthm宏包默认会在定理的计数器右下角加一个点‘.’
%使用ntheorem宏包可以自定义分隔符
\theoremseparator{分隔符}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
%导言区
%\usepackage{amsthm}
%注意在使用ntheorem宏包的时候要注释掉amsthm宏包,否则会冲突
\usepackage{ntheorem}

\theoremseparator{***} %自定义分隔符
\newtheorem{theorem}{定理}[section]

%正文区
\begin{document}

\begin{theorem}
belabela的一个定理
\end{theorem}

\end{document}

image-20220609153726207

LaTeX中的参考文献BibTex

  • thebibliography环境
1
2
3
4
5
6
7
8
%一次管理, 一次使用
\begin{thebibliography}{9}
\bibitem[记号]{引用标志} 文献条目1
\bibitem[记号]{引用标志} 文献条目2
...
\end{thebibliography}
%其中文献条目包括: 作者,题目,出版社,年代,版本,页码等.
%引用时可以采用: \cite{引用标志1, 引用标志2, ...}
1
2
3
4
\begin{thebibliography}{9}
\bibitem{3-1} 王玉杰. 自动指纹分类算法的研究[D].南京邮电大学,2012.
\bibitem{3-2} 杨利敏,杨杰,李钢.基于指纹分类的模式匹配[J].电子学报,2003(07):1030-1034.
\end{thebibliography}

Latex中thebibliography后面的数字代表的是\bibitem标签的最大宽度
标签宽度其实就是数字位数,比如1,21,123,分别是1, 2, 3个宽度
如果参考文献数量在1-9,后面的数字可以用, 1,2,3,····,9,a,b,····都可以
如果参考文献数量在10-99,后面的数字可以用,10, 21, 33,····,19,ab,bc,b0····都可以
以此类推

  • 引用方法
1
2
3
4
5
6
7
%正文引用
\cite{引用标志1,引用标志2}

%右上角引用,先定义\upcite{}命令
\newcommand{\upcite}[1]{\textsuperscript{\cite{#1}}}
%然后在正文中使用
\upcite{引用标志}
  • natbib宏包
1
2
3
4
5
6
%引用格式
\usepackage[option]{natbib}
%多个引用合并(如[3],[4],[5]变成[3-5])
\usepackage[numbers,sort&compress]{natbib}
%合并+右上角标+[](此时直接使用\cite{}就可以得到角标)
\usepackage[numbers,sort&compress,super,square]{natbib}
option 功能
round (default) 使用圆括号
square 使用方括号
curly 使用花括号
angle 使用尖括号
colon (default) 用引号分隔多个引用
comma 用逗号分隔多个引用
authoryear (default) 使用作者–年引用形式
numbers 使用编号引用形式
super 使用 Nature 那样的上标编号引用
sort 多个引用按照首字母排序
sort&compress 除排序外,多个引用可以合并 (如 3-6, 15)
longnamesfirst 多个作者的文献第一次被引用时列出所有作者,以后的引用可以缩写为 et al.
sectionbib 重定义了 \thebibliography 使用 \section* 而不是 \chapter*。这样使用 chapterbib 宏包时,参考文献名称为 section 一级
nonamebreak 在一行排版所有作者名字,这可能引起 overfull hbox 警告但是消除了跨行的 hyperref 问题
  • hyperref宏包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%hyperref宏包可以修改超链接和文献引用的字体颜色
\usepackage{hyperref}
\hypersetup{
colorlinks=true, %超链接是否带true/false
linkcolor=cyan, %目录/公式/图标等内部超链接的字体颜色
filecolor=blue, %文件型超链接的字体颜色
urlcolor=red, %网页超链接的字体颜色
citecolor=blue, %参考文献链接的字体颜色
}

%这样使用后,参考文献的链接颜色将会变成蓝色
\usepackage[colorlinks=true,
citecolor=blue,
]{hyperref}
  • BibTeX文献管理工具

使用BibTeX之前需要先在设置-构建中修改默认文献工具为BibTeX

image-20220214233344510

新建.bib文件, 在.bib文件中记录参考文献信息

LaTeX中的自定义命令和环境

  • newcommand定义新命令
1
\newcommand<命令名称>[<参数个数>][<首参数默认值>]{<具体定义>}
  • 定义命令作字符串替换
1
2
3
% 例如定义\PRC命令如下:
\newcommand \PRC{People's Republic of \emph{China}}
% 在正文中使用\PRC命令就可以得到People's Republic of China
  • 使用参数
1
2
3
4
%参数个数可以从 1 到 9, 使用时用 #1,#2,...,#9 表示
\newcommand \loves[2]{#1 喜欢 #2}
%在正文中调用如下
\loves{我}{你}

我喜欢你\newcommand \loves[2]{ #1 喜欢 #2 } \loves{我}{你}

1
2
3
4
5
6
%也可以给参数指定默认值
%但只有第一个参数可以被指定默认值
\newcommand \loves[2][我]{#1 喜欢 #2}
%在正文中调用命令
\loves{你} \qquad \loves[他]{你}
%得到下面结果

]\newcommand \loves[2][我]