LaTeX公式编号技巧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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117\documentclass[UTF8,no-math,12pt,openany,table,dvipsnames,svgnames]{article}
\usepackage{indentfirst}
\usepackage{ctex,amsmath,amssymb,mathrsfs}
\usepackage[centering,
top=2.54cm,bottom=2.54cm,right=2.9cm,left=2.9cm,
headsep=25pt,headheight=20pt]{geometry}
\setmainfont{Times New Roman}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable}
\tcbset{boxrule=0pt,sharp corners}
\usepackage[hyperindex]{hyperref}
\hypersetup{bookmarksopen=true,bookmarksopenlevel=1,bookmarksnumbered=true,
pdftitle={行间公式的编号技巧},pdfauthor={向禹},linktoc=page,
colorlinks,linkcolor=blue,citecolor=red,urlcolor=blue,anchorcolor=green}
\definecolor{structurecolor}{RGB}{0,120,2}%
\definecolor{winered}{rgb}{0.5,0,0}
\renewcommand{\ttdefault}{cmtt}
\lstdefinestyle{mystyle}{
basicstyle=%
\ttfamily
\lst@ifdisplaystyle\small\fi
}
\lstset{basicstyle=\ttfamily,style=mystyle}
\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{frenchplum}{RGB}{190,20,83}
\lstset{language=[LaTeX]TeX,
texcsstyle=*\color{winered},
numbers=none,
breaklines=true,
keywordstyle=\color{winered},
commentstyle=\color{gray},
emph={fontenc,fontspec,xeCJK,FiraMono,xunicode,newtxmath,figure,fig,image,img,table,itemize,enumerate,newtxtext,newtxtt,ctex,microtype,description,times,newtx,booktabs,tabular,PDFLaTeX,XeLaTeX,type1cm,BibTeX,device,color,mode,lang,amsthm,tcolorbox,titlestyle,cite,marginnote,ctex,listings},
emphstyle={\color{frenchplum}},
morekeywords={DeclareSymbolFont,SetSymbolFont,toprule,midrule,bottomrule,institute,version,includegraphics,setmainfont,setsansfont,setmonofont ,setCJKmainfont,setCJKsansfont,setCJKmonofont,RequirePackage,figref,tabref,email,maketitle,keywords,definecolor,extrainfo,logo,cover,subtitle,appendix,chapter,hypersetup,mainmatter,tableofcontents,elegantpar,numbers,authoryear,heiti,kaishu,lstset,pagecolor,zhnumber,marginpar,part,equote},
frame=single,
tabsize=2,
rulecolor=\color{structurecolor},
framerule=0pt,
columns=flexible,
% backgroundcolor=\color{lightgrey}
}
\numberwithin{equation}{section}
\usepackage{cases,empheq}
\begin{document}
\title{多行公式的编号技巧}\date{\empty}
\maketitle
\href{https://yuxtech.github.io/tex/amsmath.pdf}{amsmath包} 对于行间公式的输出提供了非常强大的功能,我们今天则是介绍基于\textbf{amsmath}包如何去实现特定的多行公式编号技巧.
\section{多行公式一个编号}
在换行的公式中,如果直接用\textbf{align}环境会给每行都编号, \textbf{align*}环境则每一行都没有编号.但是我们可以用\verb|\notag|命令指定某些行不编号,如
\begin{tcblisting}{sidebyside}
\begin{align}
a&=b+c\notag\\
a^2&=b^2+c^2\\
a^3&=b^3+c^3\notag
\end{align}
\end{tcblisting}
除了用\textbf{align}环境之外,我们还可以用次环境\textbf{aligned}来更好地实现这种效果
\begin{tcblisting}{sidebyside}
\begin{align}\begin{aligned}
a&=b+c\\
a^2&=b^2+c^2
\end{aligned}\end{align}
\end{tcblisting}
\textbf{aligned}环境可以看成一个盒子,我们还可以给这个盒子添加定界符
\begin{tcblisting}{sidebyside}
\begin{align}
\left\{\begin{aligned}
&a=b+c\\
&a^2=b^2+c^2
\end{aligned}\right.\end{align}
\end{tcblisting}
指定不同块按等号对齐,同时每个区块一个编号,这时用\textbf{split}次环境
\begin{tcblisting}{sidebyside}
\begin{align}
a+b&=b+c\\
\begin{split}
a&=b+c\\
a^2&=b^2+c^2
\end{split}\\
\begin{split}
a&=b+c\\
a^2&=b^2+c^2
\end{split}
\end{align}
\end{tcblisting}
一行两个公式两个编号,这种情况自然需要\textbf{minipage}环境支持了.
\begin{tcblisting}{}
\begin{minipage}{0.5\textwidth}
\begin{equation}
a^2+b^2=c^2
\end{equation}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{equation}
a^3=b^3+c^3
\end{equation}
\end{minipage}
\end{tcblisting}
给带定界符的方程组的每一行都编号,这种情况\textbf{amsmath}包无法实现,我们可以用\textbf{cases}包的\textbf{numcases}环境
\begin{tcblisting}{sidebyside}
%\usepackage{cases}
\begin{numcases}{f(x)=}%f(x)=可以置空
1,&$x\in\mathbb Q$\\
0,&$x\notin\mathbb Q$
\end{numcases}.
\end{tcblisting}
不过上述\textbf{numcases}环境的效果是不尽如人意的,更好的效果是用\textbf{empheq}包,它可以给\textbf{amsmath}包提供的数学环境添加各种定界符.
\begin{tcblisting}{sidebyside}
\begin{empheq}[left=\empheqlbrace,right=\empheqrbrack]{align}
&a=b+c&&a=b\\
&a^2=b^2+c^2&&a=b
\end{empheq}
\end{tcblisting}
\end{document}