latex
基本排版¶
table¶
table*
环境是用来创建跨双栏的浮动表格的
\resizebox{\columnwidth}{!}{...}
,这会将表格缩放到单栏的宽度
在 LaTeX 中,\textwidth
代表整个页面的文本宽度,而 \columnwidth
代表单栏的宽度。
特殊符号¶
空格¶
算法¶
宏包
格式
\begin{algorithm}
%\textsl{}\setstretch{1.8}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\caption{Iterative Solution for Training Stage}
\label{alg1}
\begin{algorithmic}[1]
\REQUIRE target user group $\mathbf{U}=\left\{u_{i}\right\}$, group set $\mathbf{G}=\left\{g_{k}\right\}$ and attendance records $\left\{s_{i, k}^{0}\right\}$
\renewcommand{\algorithmicrequire}{\textbf{Store:}}
\REQUIRE group attributes $\mathbf{a}_{k}$ for each $g_{k} \in \mathbf{G}$
\ENSURE users' profile $\left\langle\mathbf{p}_{i}, h_{i, 0}\right\rangle$ and social strength $w_{i j}$
\STATE Iteration = True;
\WHILE{Iteration}
\STATE Iteration $=$ False;
\FOR {$u \in \mathbf{U}, g_{k} \in \mathbf{G}$}
\STATE update $\left\langle\mathbf{p}_{i}, h_{i, 0}\right\rangle$ and $\left\{w_{i j}\right\}$ until convergence;
\STATE update $f_{i, k}, h_{i, k}$ based on Equation 2;
\STATE update $s_{i, k}$ as $\mathcal{I}\left(f_{i, k}-h_{i, k}\right)$;
\IF{$s_{i, k}$ changed}
\STATE Iteration $=$ True;
\ENDIF
\ENDFOR
\ENDWHILE
\end{algorithmic}
\end{algorithm}
参考文献¶
BibTex¶
BibTEX 是 LATEX 处理参考文献的传统的方式。选择“顺序编码制”或“著者-出版年制”两种格式之一
.bib 数据库,编译生成 .bbl 文件。参考文献样式(.bst 文件)
上标样式(super) ,如“张教授^[2-3] 认为⋯⋯形成了多种物理模 型^[7,9,11-13]”。 与正文平排(inline),文献序号作为叙述文字的一部分,如“张教授认为⋯⋯根据文献\([4]^{101-105}\)”
著者-出版年制的文献引用标注也有两种主要模式:
- 著者姓名作为正文的一部分,比如“Zhang (2008)”,同默认的 \cite 命令一样。
- 著者与年份均在括号中,比如“(Zhang, 2008)”。
参考文献表采用著者-出版年制组织时,各篇文献首先按文种集中,然后 按著者字顺和出版年排列;中文文献可以按著者汉语拼音字顺排列,也可以按 著者的笔画笔顺排列。但由于BibTEX功能的局限性,无法自动获取著者姓名 的拼音或笔画笔顺进行正确排序。一种解决方法是在.bib数据库的中文文献 的key 域手动录入著者姓名的拼音:
如果中文文献数量较多,推荐使用BibLaTeX处理参考文献列出所有文献(不管有没有引用)¶
适用于 BibTex 和 BibLaTex
BibLaTex¶
BibLaTeX 是较新的参考文献处理方案。需要在载入宏包时通过选择样式 (style),并且在导言区使用\addbibresource 设置数据库的路径,最后在参 考文献表的位置使用\printbibliography 输出。
对于顺序编码制,文献引用标注默认为上标样式。如果要切换为与正文平 排,一种方法是使用\parencite
,另一种是载入 biblatex 时统一设置。
其它¶
svg 图片¶
How to Use SVG Images in LaTeX | Baeldung on Computer Science
常用的包¶
amsmath(数学公式)¶
Aligning equations with amsmath - Overleaf, Online LaTeX Editor
multline
: 多行公式,\\
左侧元素左对齐,右侧元素右对齐- align: 一组公式,使用 & 对齐。每条公式都会编号
- gather:一组公式,不对齐
- aligned:用于嵌套在其它环境中,局部对齐
还是无法实现长公式和其它公式作为一组的情况。
\begin{gather}
\begin{aligned}
ActShmem = \min_{x} & \{ x \in ShmemCarveout | MaxActBlk(x) = \\
& MaxActBlk(MaxShmemPerSM) \}
\end{aligned}\\
L1\ CacheSize = L1\ Size - ActShmem
\end{gather}
使用 vspace 负值
在需要打标签的公式行末尾(通常在 \\
之前)
tikz 状态图¶
\begin{tikzpicture}[
->, >=Stealth, % 箭头样式
node distance=3cm, % 节点之间的距离
every state/.style={thick, minimum size=1.5cm}, % 状态样式
every edge/.style={draw, thick} % 边样式
]
% 节点
\node[state] (idle) {Idle};
\node[state, above right of=idle, xshift=0.5cm, yshift=0.5cm] (alloc) {Allocate};
\node[state, right of=idle, xshift=2cm] (evict) {Evict};
\node[state, below right of=idle, xshift=0.5cm] (wb) {Write Back};
% 边
\path
(idle) edge[loop left] node {Read/Write hit} (idle)
(idle) edge[bend left] node[above] {Read/Write miss, read mem} (alloc)
(alloc) edge[bend left] node[below] {allocate success} (idle)
(alloc) edge node {allocate faild} (evict)
(evict) edge node {evict clean} (idle)
(evict) edge node {evict dirty} (wb)
(wb) edge node {write mem} (idle)
;
\end{tikzpicture}
底层¶
newcommand¶
\newcommand{\helloworld}{Hello, World!}
\helloworld
\newcommand{\greet}[1]{Hello, #1!}
\greet{Alice}
\newcommand{\authorinfo}[2]{Author: #1, Email: #2}
\authorinfo{John Doe}{john.doe@example.com}
% 定义一个带一个可选参数的命令 \sectiontitle
\newcommand{\sectiontitle}[1][Default Title]{Section: #1}
\sectiontitle # 如果不提供参数,则使用默认值 "Default Title"
\sectiontitle{Introduction}
字体¶
字号¶
中文字号 | 英文字号(磅)/pt | 毫米/mm | 像素/px |
---|---|---|---|
初号 | 42 | 14.82 | 56 |
小初 | 36 | 12.7 | 48 |
一号 | 26 | 9.17 | 34.7 |
小一 | 24 | 8.47 | 32 |
二号 | 22 | 7.76 | 29.3 |
小二 | 18 | 6.35 | 24 |
三号 | 16 | 5.64 | 21.3 |
小三 | 15 | 5.29 | 20 |
四号 | 14 | 4.94 | 18.7 |
小四 | 12 | 4.23 | 16 |
五号 | 10.5 | 3.7 | 14 |
小五 | 9 | 3.18 | 12 |
六号 | 7.5 | 2.56 | 10 |
小六 | 6.5 | 2.29 | 8.7 |
七号 | 5.5 | 1.94 | 7.3 |
八号 | 5 | 1.76 | 6.7 |
ctex¶
% 用 \pkg{ctex} 的接口设置全部章节标题格式。
% 一级标题:4 号黑体,段前 8 磅,段后 8 磅。
% 一级标题:5 号黑体,段前 8 磅,段后 8 磅。
\ctexset{
section = {
format = \zihao{5},
nameformat = \heiti,
numberformat = \bfseries,
titleformat = \heiti,
% fixskip = true,
beforeskip = 8bp,
afterskip = 8bp,
afterindent = true,
},
%
% 二级标题:5 号黑体,段前 0.25 行,段后 0.25 行。
% 二级标题:小 5 号黑体,段前 0.25 行,段后 0.25 行。
subsection = {
format = \zihao{-5},
nameformat = \heiti,
numberformat = \bfseries,
titleformat = \heiti,
beforeskip = 2.625bp,
afterskip = 2.625bp,
afterindent = true,
},
%
% 三级节标题:5 号宋体,段前段后 0 磅。
subsubsection = {
format = \zihao{-5},
beforeskip = \z@,
afterskip = \z@,
afterindent = true,
},
appendix = {
name = {\appendixname\space},
},
}