1.基本语法
1.1 下标
在LaTeX中,使用argmin,argmax时,设置下标的方法:\mathop
,如\mathop{\arg\max}_{\theta}。
2. 公式
1.1 二元关系
符号 | 语法 | 符号 | 语法 | 符号 | 语法 | 符号 | 语法 |
---|---|---|---|---|---|---|---|
< | < |
> | > |
= | = |
≤ | \leq |
`` | `` | `` | `` | ||||
`` | `` | `` | `` | ||||
`` | `` | `` | `` |
1.2 字体
使公式中的字体不变倾斜:\rm
。如果要使公式中的一部分变为直体,那么要将该部分用{}括起来。不然会使公式中的全部内容变为直体。
公式编号
使用简单的align
环境。当然,您可以使用星号(*)变量来隐藏编号,并按\tag
设置特定的标记。
\documentclass{article}
\usepackage{amsmath}
\usepackage{kantlipsum}
\usepackage{showframe}
\allowdisplaybreaks
\begin{document}
\kant[1-3]
\begin{align*}
a\\
b\\
c\\
d\\
e\tag{\stepcounter{equation}\theequation}\\
f\\
g\\
h\\
i
\end{align*}
\end{document}
如果不使用星号环境,则可使用\nonumber
指定为哪一行公式不分配编号,如下所示:
\begin{eqnarray}
a\nonumber\\
b\nonumber\\
c\nonumber\\
d\nonumber\\
e\nonumber\\
f
\label{eqn:q}
\end{eqnarray}
多行公式跨页显示
可以使用\begingroup
和\endgroup
命令在本地使用amsmath的\allowdisplaybreaks
命令进行显示中断:
\begingroup
\allowdisplaybreaks
\begin{align}
% some equations
....
\end{align}
\endgroup
3. 算法
latex中与algorithm相关的包常用的有几个,algorithm
、algorithmic
、algorithmicx
、algorithm2e
,可以大致分成三类,或者说三个排版环境。最原始的是使用algorithm
+algorithmic
,这个最早出现,也是最难用的,需要自己定义一些指令。第二个排版环境是algorithm
+algorithmicx
,algorithmicx提供了一些宏定义和一些预定义好了的环境(layout),指令类似algorithmic。第三个是algorithm2e
,只需要一个包,使用起来和编程的感觉很像,也是我更倾向使用的包。下面是使用algorithm2e
的例子。
\documentclass[a4paper]{ctexart}
\usepackage[ruled]{algorithm2e}
% some others
\begin{document}
% some others
\begin{algorithm}
%\SetAlgoRefName{} % no count number
\caption{pISTA}
\label{alg:pISTA}
Parameters: $\lambda, \gamma$\;
Initialization: $x_0$\;
\While{not converge}{
$x_{k+1}=\Psi^*T_{\lambda\gamma}(\Psi(x_k+\gamma \mathcal{F}^{-1}Q_p(y-Q_p \mathcal{F}x_k)))$\;
}
\end{algorithm}
\end{document}
这里简单解释下,ruled表示显示algorithm环境的上下两条线,这个可以试下去掉和不去掉的区别。下面的\SetAlgoRefName{}表示不显示标题(caption)的Algorithm编号,也就是说将原来的Algorithm n:
变成Algorithm:
。更多的使用说明,可以直接查阅官方文档。
algorithm是浮动的,不能放盒子(如tcolorbox)里面。如果需要这种样子,改用\begin{algorithm}[H]
,否则出现LaTeX Error: Not in outer par mode错误。
4. 文本框
tcolorbox
宏包是一个用于绘制彩色文本框的宏包。示例如下:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{most}
\begin{document}
\begin{tcolorbox}[title = {My Box},
fonttitle = \bfseries, fontupper = \sffamily, fontlower = \itshape]
This is a \textbf{tcolorbox}.
\tcblower
This is the lower part.
\end{tcolorbox}
\end{document}
LaTex学习资源
muzimuzhi/latex-examples [github]