本文介绍了latex中常用的功能
符号大全
因为符号更常用,所以放到前面了。
优秀案例
\begin{equation}
\begin{aligned}
\arg\max _{y_{poison}}&\lVert \textbf{g}_{poison} -\textbf{g}_{clean} \rVert_{2} \\
\mathrm{where~~} &y_{poison} = (1-\alpha) y_{dev} + \alpha y_{clean}\\
&\textbf{g}_{poison} = \nabla\mathcal{L}(f(\textbf{x}), y_{poison})\\
&\textbf{g}_{clean} = \nabla\mathcal{L}(f(\textbf{x}), y_{clean})\\
s.t.~~ &\alpha \in [0,1]\\
&\arg\max_k y_{clean}^{k} = \arg\max_k y_{poison}^{k}\\
\end{aligned}
\end{equation}
字母样式
第一行是罗马体,第二行是斜体,第三行类似于斜体
斜体(强烈推荐用于文本)
语法 \textit{Precision}
:
Precision
\textit{Precision}
Precision
语法 \emph{Precision}
:
正粗体(强烈推荐用于文本)
语法 \textbf{Precision}
:
Precision
\textbf{Precision}
Precision
斜粗体(强烈推荐用于文本)
语法 \textbf{\textit{Precision}}
:
Precision
\textbf{\textit{Precision}}
Precision
语法 \textbf{\emph{Precision}}
:
上述三种用于文本,其余用于公式
正粗体
语法 \mathbf{012…abc…ABC…}
:
012
…
a
b
c
x
…
A
B
C
X
…
\mathbf{012…abcx…ABCX…}
012…abcx…ABCX…,对比下\textbf{012…abcx…ABCX…}
:
012
…
abcx
…
ABCX
…
\textbf{012…abcx…ABCX…}
012…abcx…ABCX…,好像效果一样!
斜粗体
语法 \boldsymbol{012…abc…ABC…\alpha \beta\gamma…}
:
012
…
a
b
c
x
…
A
B
C
X
…
α
β
γ
…
\boldsymbol{012…abcx…ABCX…\alpha \beta\gamma…}
012…abcx…ABCX…αβγ…
注意:
- 英文字母 “L” 的小写 “l” 很容易和1搞混,因此我们一般使用
\ell
来代替 l,效果: ℓ \ell ℓ。 - 数域⽤\mathbb{R}( R \mathbb{R} R),\mathbb{Z}( Z \mathbb{Z} Z)。
- \boldsymbol{x} 组成的集合⽤\mathcal{X}( x ∈ X \boldsymbol{x} \in \mathcal{X} x∈X),a 组成的集合⽤ A( a ∈ A a \in A a∈A)
- 公式中的 softmax,proj,enc 等,超过⼀个字⺟的变量或符号,要⽤正⽂字体,即写成 \textrm{softmax} 或 \textit{FFN}。
- 公式中的括号,要⽤\left,\right 进⾏标记。如 \left(\right),\left{ \right}。<>、|| 这种 括号也是⼀样的。括号中的分割可以搭配\middle。如下图:
分式、矩阵、多项式
语法 | 效果 |
---|---|
\frac{2}{4}=0.5 | 2 4 = 0.5 \frac{2}{4}=0.5 42=0.5 |
\cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} =a | 2 c + 2 d + 2 4 = a \cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} =a c+d+4222=a |
\dbinom{n}{r}=\binom{n}{n-r}=Cn_r=Cn_{n-r} | ( n r ) = ( n n − r ) = C r n = C n − r n \dbinom{n}{r}=\binom{n}{n-r}=C^n_r=C^n_{n-r} (rn)=(n−rn)=Crn=Cn−rn |
矩阵 | |
![]() | |
![]() | |
![]() |
重音符号(向量符号)
希腊字母
二元关系
运算符
大运算符(积分求和)
箭头
定界符(括号)
如何打出大定界符?:
在 \lVert 内容 \rVert
中,加上: \left\lVert 内容 \right\rVert
。
加上 \left \right 后,定界符的大小就会自动调整了。
其他符号
\Delta:
Δ
\Delta
Δ
前置上下标:
1
2
X
3
4
{}_1^2\!X_3^4
12X34
基本结构
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{comment}
% Title
\title{Document Title} %标题
\author{Rooney \thanks{Somebody}}
\date{2020-05-09}
\begin{document}
\begin{titlepage}
\maketitle
\end{titlepage}
\tableofcontents
\begin{abstract}
This is a simple paragraph at the beginning of the
document. A brief introduction about the main subject.
\end{abstract}
First document. This is a simple example, with no
extra parameters or packages included.
% Comments
\begin{comment}
This text won't show up in the compiled pdf
this is just a multi-line comment. Useful
to, for instance, comment out slow-rendering
while working on the draft. 相当于加强版的 %
\end{comment}
\end{document}
其中,\documentclass命令是用于设置LaTex文件所生成文档的格式. 其命令语法如下所示: \documentclass[options]{class}
常见的class可选项:
class | 文体 |
---|---|
article | 科技论文,报告,软件文档等 |
IEEEtran | IEEE Transactions 格式. |
report | 长篇报告(如:学位论文) |
常见的option可选项:
option | 內容 |
---|---|
12pt | 文档正文使用的字体大小(默认为10pt) |
twoside, oneside | 分成几列,一般期刊论文是两列 |
report | 长篇报告(如:学位论文) |
注释
先加载宏包:
\usepackage{comment}
一般用 % 注释一段话,看也可以用\begin{comment} 注释内容 \end{comment }来注释好几段话。
换行
两个反斜杠 \
空格
波浪线~
换行不缩进
\noindent
效果:
中文
将WinEdt设置为默认使用UTF8格式打开tex文件。
如果WinEdt打开一个UTF-8格式的文件显示乱码,可在Document->Document Setting->Format->File Format中选择UTF-8
或者在在该文件的开始处添加一行
% !Mode:: "TeX:UTF-8"
Latex环境中使用中文需要注意的一点是: Latex编辑器读入文件的使用的编码格式一定要与该文件的编码格式一致。
1.使用ctexart
\documentclass[UTF8]{ctexart}
\usepackage{CJK}
\begin{document}
Hello, World!
世界, 你好!
\emph{世界, 你好!} %斜体
\textbf{世界, 你好!} % 粗体
{\CJKfamily{hei} 黑体}
{\CJKfamily{kai} 楷体}
{\CJKfamily{li} 隶书}
{\CJKfamily{fs} 仿宋}
{\CJKfamily{song} 宋体}
\end{document}
2.使用CTEX中文包(UTF8格式)
\documentclass[UTF8]{article}
\usepackage{CTEX}
\begin{document}
\section{字体设置}
{\kaishu 楷体}
{\songti 宋体}
{\heiti 黑体}
{\fangsong 仿宋}
\end{document}
算法
先加载宏包:
\usepackage{algorithm}
\usepackage{algorithmic}
\renewcommand{\algorithmicrequire}{ \textbf{Input:}} % Input 代替 Require
\renewcommand{\algorithmicensure}{ \textbf{Initialize:}} % Initialize 代替 Ensure
\renewcommand{\algorithmicreturn}{ \textbf{Output:}} % Output 代替 Return
\begin{algorithm}
\caption{Title of the Algorithm}
\label{algo:ref}
\begin{algorithmic}[1]
\REQUIRE some words. % this command shows "Input"
\ENSURE ~\\ % this command shows "Initialized"
some text goes here ...\\
\WHILE {\emph{not converged}}
\STATE ... \\ % line number at left side
\ENDWHILE
\RETURN this is the lat part. % this command shows "Output"
\end{algorithmic}
\end{algorithm}
还有一种更简便的不用修改宏包的办法:
\begin{algorithm}[t]
\caption{Fingerprint Filtering}
\label{alg:algorithm2}
\begin{flushleft}
\textbf{Input}: $M_{\mathit{tgt}}, \mathcal{A}, D_{\mathit{tgt}}$ \\
\textbf{Output}: $D_{\mathit{fp}}$
\end{flushleft}
\begin{algorithmic}[1] %[1] enables line numbers
\STATE $k=0$
\STATE $D_{\mathit{fp}} \gets \emptyset$
\FOR{\textbf{each} $F \in M_{\mathit{tgt}}$ }
\STATE $k=k+1$
\STATE $S_k \gets \emptyset$
\FOR{\textbf{each} $\mathbf{x} \in D_{\mathit{tgt}}$ }
\STATE $y_{\mathit{tgt}} = F(\mathbf{x})$
\IF {$\mathcal{A}(y_{\mathit{tgt}}) = $ ``In''}
\STATE $S_k \gets S_k \cup \mathbf{x}$
%\STATE $D_{\mathit{finger}} \gets D_{\mathit{finger}} \cup \mathbf{x}$
\ENDIF
%\STATE $S_{k} \gets S_{k} \cup Y_{\mathit{tgt}}$
\ENDFOR
%\STATE $S_{k} \gets S_{k} \cup Y_{\mathit{tgt}}$
\ENDFOR
\STATE $D_{\mathit{fp}} = S_{1} \cap S_{2} \cap ... \cap S_{k} $
\STATE \textbf{return} $D_{\mathit{fp}}$
\end{algorithmic}
\end{algorithm}
另一个模板:
%=======================算法代码=========================
\begin{algorithm}[t]
\caption{\emph{The pseudo-code
of P$^2$-Protection}}
\label{alg:algorithm1}
\textbf{Require:} the trained FL global model $f$ \\
\textbf{Output:} the protected FL global model $\hat{f}$
\begin{algorithmic}%[1] %[1] enables line numbers
\STATE \noindent \textbf{FL client executes:}
\FOR{each client $C_{i}, i\in \{1,2, \cdots, M\}$ \textbf{in parallel}}
% \STATE $\mathbf{w}_{poison}^{i} = 0$
\FOR{ each local training data $(\textbf{x},y)$ }
\STATE $y_{clean} \leftarrow f(\textbf{x})$
\STATE $y_{dev} \leftarrow \mathrm{MGD}(f,(\textbf{x}, y_{clean}))$ %\quad//~ Search the deviation vector
\STATE $y_{poison} = \mathrm{PoisonPrediction}(y_{dev},y_{clean})$ %\quad//~ The value of $\alpha$ is discussed in $XX$
\STATE $\mathbf{w}_{poison}^{i} = \mathrm{ComputeUpdate}(f, (\textbf{x},y_{poison}))$ %\quad //~Get the local poisoning updates of all training data
\ENDFOR
\ENDFOR
\RETURN $\mathbf{w}_{poison}^{i}$
\STATE
\STATE \noindent \textbf{FL server executes:}
\STATE $\mathbf{W}_{poison} = \emptyset$
\FOR{each client $C_{i}, i\in \{1,2, \cdots, M\}$ }
\STATE $\mathbf{W}_{poison} = \mathbf{W}_{poison} \cup \mathbf{w}^{i}_{poison}$ \quad//~Updates collecting
\ENDFOR
\STATE $\hat{f} = f + \sum^{M}_{i=1} \alpha_i \mathbf{w}_{poison}^{i}$ \quad//~Model updating
\RETURN $\hat{f}$
\STATE
\end{algorithmic}
\end{algorithm}
%=======================算法代码=========================
表格注释
需要加载一个包:\usepackage{algpseudocode}
然后在算法来里头用 \Comment{ 内容 }
指令进行注释即可:
表格
需要加载宏包:
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{threeparttable} %三线表格
\usepackage{diagbox} %斜对角线
\usepackage{array}
示例一:
\begin{table}[h]
\centering %居中表格
\caption{this is my table}
\begin{tabular}{llr} %%前两列左对齐,第三列右对齐
%也可以设置每一列的宽度 \begin{tabular}{p{3.5cm}|p{2cm}|p{5cm}}
%也可以设置表格总宽度的宽度 \begin{tabularx}{12cm}
\hline
\multicolumn{2}{c}{Item} \\ %Item写于前两列的合并
\cline{1-2} %只画前两行的横线
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
\end{table}
代码第四行决定表格中内容的对齐形式:
\begin{tabular}[pos]{table spec}
table spec选项:
table spec | 作用 | 样例 |
---|---|---|
l | 左对齐 | {l c r} |
c | 居中 | {l c r} |
r | 右对齐 | {l c r} |
p | 限制列宽 |
表格内容中的一些符号作用
符号 | 作用 |
---|---|
& | 列分隔 |
\ | 新列 |
\hline | 画一条水平线 |
\newline | 在列中换行 |
\cline{i-j} | 在水平方向从第 i 列 到 第 j 列画横线段 |
表格中行间距
\renewcommand{\arraystretch}{1.5} %默认是1.0
示例二:三线表格(更常用)
\begin{table}[h]
\caption{This my second table}
\centering
\begin{tabular}{ccc}
\toprule %命令是画出表格最上边的一条粗实线(rule)
Name & ID & Gender\\
\midrule % 命令是画出表格中间的细实线。 效果如下图所示:
Tom & 001& Male\\
Rose & 002& Female\\
\bottomrule %命令是画出表格最下边的一条粗实线.
\end{tabular}
\end{table}
示例三:跨越两栏的多表格
如何跨越?——\begin{table}[h ]改成 \begin{table*}[h]
多表格的设置有点巧妙:
在这里插入代码片
注意
展示数据的列,如果数据不等⻓,请右对⻬。(下图左边是错误地做左对⻬的示例,右边 为正确的)
表格中的加粗请使⽤ \textbf{},⽽⾮\bf。上图右边中,14.10的加粗就错误地使⽤了\bf, 导致对⻬出现问题(这⼀问题仅在某些模板中存在),⽽17.24的加粗就使⽤了\textbf{}。
表格字体大小
插入\begin{table}[h] 和 \begin{tabular}之间。
\tiny
\scriptsize
\footnotesize
\small
\normalsize % 默认
\large
\Large
\LARGE
\huge
\Huge
或者用数字表示:
\fontsize{8}{10}\selectfont % 8是字号大小,10是行间距
表格线条粗细
最简单的加粗方式,直接对三条线进行加粗:\toprule \midrule \bottomrule
,加粗方法如下:
\begin{table}
\centering
\fontsize{8}{10}\selectfont
%\vspace{1.0mm}
\caption{}
\begin{tabular}{|c|c|c|c|}
\toprule[2mm]
\textbf{Dataset} & \textbf{No defense} & \textbf{DP} & \textbf{MAD} \\\midrule[0.8mm]
Adult&&& \\
Purchase20&&& \\
FEMNIST&&& \\
\bottomrule[2mm]
\end{tabular}
\end{table}
但是这样存在一个问题,竖线和横线之间存在空袭,为了解决这个问题,我们需要引入 \usepackage{makecell}
这个包放在最前面,然后使用 \Xhline{1.2pt}
来代替原来的 \hline
:
\begin{table}
\centering
\fontsize{8}{10}\selectfont
%\vspace{1.0mm}
\caption{}
\begin{tabular}{|c|c|c|c|}
\Xhline{1.2pt}
\textbf{Dataset} & \textbf{No defense} & \textbf{DP} & \textbf{MAD} \\\Xhline{1.2pt}
Adult&&& \\
Purchase20&&& \\
FEMNIST&&& \\
\Xhline{1.2pt}
\end{tabular}
\end{table}
单元格内换行
\shortstack{ 第一行的內容 \ 第二行的内容 }
{\emph{Suspect}} & \shortstack{Authenticate \\ Accuracy} & {\emph{Authenticate Accuracy}} & \shortstack{First line\\(second line)} \\
设置表格总长
\begin{table}
\caption{设置表格总长}
\begin{tabular*}{12cm}{lll}
\hline
Start & End & Character Block Name \\
\hline
3400 & 4DB5 & CJK Unified Ideographs Extension A \\
4E00 & 9FFF & CJK Unified Ideographs \\
\hline
\end{tabular*}
\end{table}
设置表格总长是12cm
表格内自动换行(限制列宽)
\begin{document}
\begin{table}
\caption{自动换行}
\begin{center}
\begin{tabular}{|l|l|l|l| p{5cm}|} % p{5cm}改成m{0.08\textwidth}也行
\hline
Item & Name & Gender & Habit & Self-introduction \\ \hline
1 & Jimmy & Male & Badminton & Hi, everyone,my name is Jimmy. I come from Hamilton,
and it's my great honour to give this example. My topic is about how to use p{width} command \\ \hline
2 & Jimmy & Male & Badminton & Hi, everyone,my name is Jimmy. I come from Hamilton,
and it's my great honour to give this example. My topic is about how to use p{width} command \\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{tabular}{|l|l|l|l| p{5cm}|}设置最后一列最大是5cm,超出部分要换行。注意,只能使用p限制列宽。p也可以用m代替,p是限制列宽的的左对齐,m是限制列宽的右对齐。
设置表格宽度(所有大表格请务必这么操作一下)
方法1
需要导入graphicx包:\usepackage{graphicx}
:使用 \resizebox{1.0\linewidth}{内容}
命令包围tabular的内容,其中,1.0表示将表格的宽度设置为页面宽度(linewidth);如果是0.8的话,那么表格的宽度将被设置为页面宽度的80%;类似的,数值越小,表格宽度越小;当然,也可以设置比1.0还大的数字,但那样的话就不够美观了,因为给人还会是一种表格越界的感觉。
\begin{table}
\centering
\caption{A Table Demo}
\label{tab_demo}
\resizebox{1.0\linewidth}{!}{ % 在 label之后,tabular之前加
\begin{tabular}{ccccccccccc}
\hline
Animal & Weight & Color & Weight & Color & Weight & Color & Weight & Color & Weight & Color\\
\hline
Dog & 20.1 & White & 18.0 & Gray & 30.5 & Black & 30.5 & Black& 30.5 & Black\\
Cat & 10.2 & Yellow & 11.2 & Black & 11.5 & White & 11.5 & White& 11.5 & White\\
Fox & 15.5 & Gold & 15.6 & Gold & 16.5 & Gold & 16.5 & Gold & 16.5 & Gold\\
Duck & 2.4 & White & 3.0 & White & 4.0 & White & 4.0 & White& 4.0 & White\\
\hline
\end{tabular}
}
\end{table}
方法2
需要用到 \usepackage{tabularx,multirow},注意,这里是tabularx
\begin{table}
\caption{表格宽度X}
\begin{tabularx}{10cm}{llX} % 10cm 減去前兩個欄位寬度後,剩下的通通給
\hline % 第三欄位使用,文字超出的部份會自動折行
Start & End & Character Block Name \\
\hline
3400 & 4DB5 & CJK Unified Ideographs Extension A \\
4E00 & 9FFF & CJK Unified Ideographs \\
\hline
\end{tabularx}
\end{table}
调整行高
在该行内容开始之前添加以下命令即可:\rule{0pt}{15pt}
0pt 的意义无需太多关心,15pt 表示行高。
设置表格某列的宽度
注意,只能使用p限制列宽。p也可以用m代替,**p是限制列宽的的左对齐,m是限制列宽的右对齐。
\begin{table}[h] %开始一个表格environment,表格的位置是h,here。
\caption{改变表格任一列宽} %显示表格的标题
\begin{tabular}{p{3.5cm}|p{2cm}|p{5cm}} %设置了每一列的宽度,强制转换。
\hline
\hline
Format & Extension & Description \\ %用&来分隔单元格的内容 \\表示进入下一行
\hline %画一个横线,下面的就都是一样了,这里一共有4行内容
Bitmap & .bmp & Bitmap images are recommended because they offer the most control over the exact image and colors.\\
\hline
Graphics Interchange Format (GIF) & .gif & Compressed image format used for Web pages. Animated GIFs are supported.\\
\hline
Joint Photographic Experts Group (JPEG) & .jpeg, .jpg & Compressed image format used for Web pages.\\
\hline
Portable Network Graphics (PNG) & .png & Compressed image format used for Web pages.\\
\hline
\hline
\end{tabular}
\end{table}
如果又要设定列宽又要居中,得在p{2cm}后面添加<{\centering}:
\begin{table}[h] %开始一个表格environment,表格的位置是h,here。
\caption{改变表格任一列宽+居中} %显示表格的标题
\begin{tabular}{p{3.5cm}<{\centering}|p{2cm}<{\centering}|p{5cm}<{\centering}} %设置了每一列的宽度,强制转换。
\hline
\hline
Format & Extension & Description \\ %用&来分隔单元格的内容 \\表示进入下一行
\hline %画一个横线,下面的就都是一样了,这里一共有4行内容
Bitmap & .bmp & Bitmap images are recommended because they offer the most control over the exact image and colors.\\
\hline
Graphics Interchange Format (GIF) & .gif & Compressed image format used for Web pages. Animated GIFs are supported.\\
\hline
Joint Photographic Experts Group (JPEG) & .jpeg, .jpg & Compressed image format used for Web pages.\\
\hline
Portable Network Graphics (PNG) & .png & Compressed image format used for Web pages.\\
\hline
\hline
\end{tabular}
\end{table}
高端的三线表格
\begin{table}[tp]
\centering
\fontsize{6.5}{8}\selectfont
\begin{threeparttable}
\caption{Demographic Prediction performance comparison by three evaluation metrics.}
\label{tab:performance_comparison}
\begin{tabular}{ccccccc}
\toprule
\multirow{2}{*}{Method}&
\multicolumn{3}{c}{ G}&\multicolumn{3}{c}{ G}\cr
\cmidrule(lr){2-4} \cmidrule(lr){5-7} %为该行的某几行划横线,其中,lr改成r可能会更好~
&Precision&Recall&F1-Measure&Precision&Recall&F1-Measure\cr
\midrule
kNN&0.7324&0.7388&0.7301&0.6371&0.6462&0.6568\cr
F&0.7321&0.7385&0.7323&0.6363&0.6462&0.6559\cr
E&0.7321&0.7222&0.7311&0.6243&0.6227&0.6570\cr
D&0.7654&0.7716&0.7699&0.6695&0.6684&0.6642\cr
C&0.7435&0.7317&0.7343&0.6386&0.6488&0.6435\cr
B&0.7667&0.7644&0.7646&0.6609&0.6687&0.6574\cr
A&{\bf 0.8189}&{\bf 0.8139}&{\bf 0.8146}&{\bf 0.6971}&{\bf 0.6904}&{\bf 0.6935}\cr
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\multirow参数:
\multirow{nrows}[bigstructs]{width}[fixup]{text}
nrows 设定所占用的行数。
bigstructs 此为可选项,主要是在你使用了 bigstruct 宏包时使用。
width 设定该栏文本的宽度。如果想让 LaTeX 自行决定文本的宽度,则用 * 即可。
fixup 此为可选项,主要用来调整文本的垂直位置。
text 所要排版的文本。可用 \\ 来强迫换行。
多个小表格组合
1.一个table夹带多个tabular
\begin{table}
\centering
{\centerline{\bf (a). CDR samples}}
\vspace{1.0mm}
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{record-id} & \textbf{user-id} & \textbf{online-time} & \textbf{offline-time} \\\hline
1 & \#user-1 & \#timestamp-1 & \#timestamp-2 \\\hline
2 & \#user-2 & \#timestamp-3 & \#timestamp-4 \\\hline
3 & \#user-2 & \#timestamp-5 & \#timestamp-6 \\\hline
4 & \#user3 & \#timestamp-7 & \#timestamp-8 \\\hline
\vdots & \vdots & \vdots &\vdots\\\hline
\end{tabular}
\vspace{3mm}
\centering
\centerline{\bf (b). DTR samples}
\vspace{1.0mm}
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{record-id} & \textbf{user-id} & \textbf{online-time} & \textbf{offline-time} \\\hline
1 & \#user-1 & \#timestamp-1 & \#timestamp-2 \\\hline
2 & \#user-2 & \#timestamp-3 & \#timestamp-4 \\\hline
3 & \#user-2 & \#timestamp-5 & \#timestamp-6 \\\hline
4 & \#user3 & \#timestamp-7 & \#timestamp-8 \\\hline
\vdots & \vdots & \vdots &\vdots\\\hline
\end{tabular}
\vspace{3mm}
\centering
\centerline{\bf (c). DTR samples}
\vspace{1.0mm}
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{record-id} & \textbf{user-id} & \textbf{online-time} & \textbf{offline-time} \\\hline
1 & \#user-1 & \#timestamp-1 & \#timestamp-2 \\\hline
2 & \#user-2 & \#timestamp-3 & \#timestamp-4 \\\hline
3 & \#user-2 & \#timestamp-5 & \#timestamp-6 \\\hline
4 & \#user3 & \#timestamp-7 & \#timestamp-8 \\\hline
\vdots & \vdots & \vdots &\vdots\\\hline
\end{tabular}
\vspace{1.5mm}
\caption{CDR (Call Detail Records) and DTR (Data Traffic Records) samples.}
\end{table}
2.figure夹带多个tabular
\begin{figure}
\centering
{\centerline{\bf (a). CDR samples}}
\vspace{1.0mm}
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{record-id} & \textbf{user-id} & \textbf{online-time} & \textbf{offline-time} \\\hline
1 & \#user-1 & \#timestamp-1 & \#timestamp-2 \\\hline
2 & \#user-2 & \#timestamp-3 & \#timestamp-4 \\\hline
3 & \#user-2 & \#timestamp-5 & \#timestamp-6 \\\hline
4 & \#user3 & \#timestamp-7 & \#timestamp-8 \\\hline
\vdots & \vdots & \vdots &\vdots\\\hline
\end{tabular}
\vspace{3mm}
\centering
\centerline{\bf (b). DTR samples}
\vspace{1.0mm}
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{record-id} & \textbf{user-id} & \textbf{online-time} & \textbf{offline-time} \\\hline
1 & \#user-1 & \#timestamp-1 & \#timestamp-2 \\\hline
2 & \#user-2 & \#timestamp-3 & \#timestamp-4 \\\hline
3 & \#user-2 & \#timestamp-5 & \#timestamp-6 \\\hline
4 & \#user3 & \#timestamp-7 & \#timestamp-8 \\\hline
\vdots & \vdots & \vdots &\vdots\\\hline
\end{tabular}
\vspace{3mm}
\centering
\centerline{\bf (c). DTR samples}
\vspace{1.0mm}
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{record-id} & \textbf{user-id} & \textbf{online-time} & \textbf{offline-time} \\\hline
1 & \#user-1 & \#timestamp-1 & \#timestamp-2 \\\hline
2 & \#user-2 & \#timestamp-3 & \#timestamp-4 \\\hline
3 & \#user-2 & \#timestamp-5 & \#timestamp-6 \\\hline
4 & \#user3 & \#timestamp-7 & \#timestamp-8 \\\hline
\vdots & \vdots & \vdots &\vdots\\\hline
\end{tabular}
\vspace{1.5mm}
\caption{CDR (Call Detail Records) and DTR (Data Traffic Records) samples.}
\end{figure}
注意:题注变成了图一
3.一个tabular布局多个表格
比较麻烦,但是好控制:
\begin{table*}
\scriptsize
\centering
% \fontsize{8}{15}\selectfont %{字体尺寸}{行距}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\multicolumn{10}{c}{ (a).Adult} \vspace{0.5mm}%调整间距
\\\hline
\multirow{2}{*}{Metrics}& \multicolumn{8}{c|}{Ours}& \multirow{2}{*}{\shortstack{ Merrer et al. \\ (DNN Only)}}\\\cline{2-9}
&\multicolumn{1}{c|}{XGB}&{DT}&LR1&LR2&SVM&DNN&RF&Average&\\\cline{1-10}
%在第2列到第5列下面划线
\multicolumn{1}{|c|}{Authentication Accuracy} &100.0\%&100.0\%&50.0\%&100.0\%&100.0\%&50.0\%&100.0\%&85.70\%&100.0\%\\\hline
\multicolumn{1}{|c|}{Original Classification Accuracy} &86.1\%&84.5\%&82.4\%&78.6\%&77.9\% &76.5\%&85.1\%&81.6\%&85.33\%\\\hline
\multicolumn{1}{|c|}{Classification Accuracy Decline} &
\diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & 0.41\%\\\hline
\multicolumn{10}{c}{~}\\
% Mnist dataset
\multicolumn{10}{c}{ (b).Mnist} \vspace{0.5mm}%调整间距
\\\hline
\multirow{2}{*}{Metrics}& \multicolumn{8}{c|}{Ours}& \multirow{2}{*}{\shortstack{ Merrer et al. \\ (CNN Only)}}\\\cline{2-9}
&\multicolumn{1}{c|}{XGB}&{DT}&LR1&LR2&SVM&DNN&RF&Average&\\\cline{1-10}
%在第2列到第5列下面划线
\multicolumn{1}{|c|}{Authentication Accuracy} &100.0\%&100.0\%&50.0\%&100.0\%&100.0\%&50.0\%&100.0\%&85.7\%&100.0\%\\\hline
\multicolumn{1}{|c|}{Original Classification Accuracy} &86.1\%&84.5\%&82.4\%&78.6\%&77.9\% &76.5\%&85.1\%&81.6\%&99.5\%\\\hline
\multicolumn{1}{|c|}{Classification Accuracy Decline} &
\diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & 2.73\%\\\hline
\multicolumn{9}{c}{~}\\
% purchase50 dataset
\multicolumn{10}{c}{ (c).Purchase50} \vspace{0.5mm}%调整间距
\\\hline
\multirow{2}{*}{Metrics}& \multicolumn{8}{c|}{Ours}& \multirow{2}{*}{\shortstack{ Merrer et al. \\ (CNN Only)}}\\\cline{2-9}
&\multicolumn{1}{c|}{XGB}&{DT}&LR1&LR2&SVM&DNN&RF&Average&\\\cline{1-10}
%在第2列到第5列下面划线
\multicolumn{1}{|c|}{Authentication Accuracy} &100.0\%&100.0\%&50.0\%&100.0\%&100.0\%&50.0\%&100.0\%&85.7\%&62.60\%\\\hline
\multicolumn{1}{|c|}{Original Classification Accuracy} &86.1\%&84.5\%&82.4\%&78.6\%&77.9\% &76.5\%&85.1\%&81.6\%&87.36\%\\\hline
\multicolumn{1}{|c|}{Classification Accuracy Decline} &
\diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & 3.71\%\\\hline
\multicolumn{9}{c}{~}\\
% purchase100 dataset
\multicolumn{10}{c}{ (d).Purchase100} \vspace{0.5mm}%调整间距
\\\hline
\multirow{2}{*}{Metrics}& \multicolumn{8}{c|}{Ours}& \multirow{2}{*}{\shortstack{ Merrer et al. \\ (CNN Only)}}\\\cline{2-9}
&\multicolumn{1}{c|}{XGB}&{DT}&LR1&LR2&SVM&DNN&RF&Average&\\\cline{1-10}
%在第2列到第5列下面划线
\multicolumn{1}{|c|}{Authentication Accuracy} &100.0\%&100.0\%&50.0\%&100.0\%&100.0\%&50.0\%&100.0\%&85.7\%&55.0\%\\\hline
\multicolumn{1}{|c|}{Original Classification Accuracy} &86.1\%&84.5\%&82.4\%&78.6\%&77.9\% &76.5\%&85.1\%&81.6\%&83.63\%\\\hline
\multicolumn{1}{|c|}{Classification Accuracy Decline} &
\diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & \diagbox[dir=SW]{}{} & 3.0\%\\\hline
\multicolumn{9}{c}{~}\\
\end{tabular}
\label{tab1}
\caption{Authentication results for multiple datasets}
\end{table*}
斜线方向的设定
https://www.jianshu.com/p/f357142fc515
\begin{tabular}{|l|c|c|c|}
\hline
\diagbox{学科}{成绩}{姓名} & ABC & BBC & CED \\
\hline
数学 & 99 & 89 & \diagbox{ce1}{ce2} \\
\hline
化学 & \diagbox[dir=SW]{ce3}{ce4} & 67 & 82 \\ % 注意方向参数是[]
\hline
\end{tabular}
有时候斜线会出现不对齐的情况:
在 \diagbox 后加入[trim=l,width=16em],通过不断调整width参数,可以对齐:
在这里插入代码片
调整间距
以下的命令都放在 \begin{tabular} 之前
表格段后间距调整
\setlength{\baselineskip}{1.5em} % 行间距
表格段前间距调整
\setlength{\parskip}{2.0ex} % 段间距
表格列宽度的调整
\renewcommand\tabcolsep{5.0pt} % 调整表格列间的长度 可以用7mm代替5.0pt
调整表格整体宽度,这里用的时候要注意
\resizebox{\textwidth}{15mm}{
\begin{tabular}{cccccccccccc}
。。。。。。表格內容
\end{tabular}}
调整单个单元格宽度:
\begin{tabular}{| l | c | c | c || p{1.5cm} |}
各类表格模板大全
见:
https://blog.csdn.net/weixin_42468475/article/details/113987015
图片
\usepackage[pdftex]{graphicx}
% 设置图片文件存放路径
\graphicspath{../figures}
\begin{document}
% 在正文中引用图片时使用\ref
In Figure \ref{fig:foo}
\begin{figure}
%设置对齐格式
\centering %图片居于页面中部
%指定图形大小和图形名称
\includegraphics [width=0.8,height=2.5]{foo.png}
%设置标题
\caption{Foo}
%设置图形引用名称
\label{fig:foo}
\end{figure}
\end{document}
插入pdf格式的图片:
添加包 \usepackage{graphicx}
\begin{figure}[htbp]
\centering
\includegraphics[height=4.5cm, width=7.5cm]{pdf_file}
\caption{Design}
\end{figure}
# 其中,pdf_file表示要插入的pdf图片文件名,不需要加后缀。
更高级的插图
一行插2图
注意,有两种包支持一行插2图,分别是 \usepackage{subfigure} 和 \usepackage{subcaption},但是这两种包不兼容(不能同时导入,不然会报错)!!!
使用 \usepackage{subcaption}
\usepackage{subcaption}% 提前导入包
% \usepackage{subfigure} % 记得把这个包屏蔽,和subcaption不兼容
\begin{figure}
\centering
\begin{subfigure}{0.47\linewidth}
\centering
\includegraphics[width=1.55in]{figs/fine-tune_cifar10.jpg}
\caption{CIFAR-10}
\end{subfigure}
\hspace{-2pt}
\begin{subfigure}{0.47\linewidth}
\centering
\includegraphics[width=1.55in]{figs/fine-tune_ImageNet.jpg}
\caption{ImageNet}
\end{subfigure}
\caption{Fingerprint detection rate over different fine-tuning epochs on CIFAR-10 and ImageNet models. The gray area represents the range of fingerprint detection rate for $50$ (CIFAR-10) and $10$ (ImageNet) negative models.}
\label{Fig:fine-tune}
\end{figure}
使用 \usepackage{subfigure}
\usepackage{subfigure} % 提前导入包
\begin{figure} %这里用figure就是占据两列
\centering
\subfigure[XGB]{
\includegraphics[width=3cm]{The impact of epsilon attack acc.jpg}}
\subfigure[DT]{
\includegraphics[width=3cm]{The impact of epsilon prediction acc.jpg}}
\caption{MainfigureCaption}
\end{figure}
如果不像要子图的子标题a和b,可以这样:
\begin{figure}
\centering
\subfigure{
\includegraphics[width=4cm]{The impact of epsilon attack acc.jpg}}
\subfigure{
\includegraphics[width=4cm]{The impact of epsilon prediction acc.jpg}}
\caption{The impact of $\epsilon$. }
\end{figure}
插入多组图片并实现自动编号:
首先使用宏包:
\usepackage{graphicx}
\usepackage{subfigure}
竖向插入
\begin{figure}
\centering
\subfigure[the first subfigure]{
\begin{minipage}[b]{0.2\textwidth}
\includegraphics[width=1\textwidth]{fig1.eps} \\
\includegraphics[width=1\textwidth]{fig2.eps}
\end{minipage}}
\subfigure[the second subfigure]{
\begin{minipage}[b]{0.2\textwidth}
\includegraphics[width=1\textwidth]{fig3.eps} \\
\includegraphics[width=1\textwidth]{fig4.eps}
\end{minipage}}
\end{figure}
横向插入
\begin{figure}
\begin{minipage}[t]{0.5\linewidth}
\centering
\includegraphics[width=2.2in]{fig1.eps}
\caption{fig1}
\label{fig:side:a}
\end{minipage}%
\begin{minipage}[t]{0.5\linewidth}
\centering\includegraphics[width=2.2in]{fig2.eps}
\caption{fig2}
\label{fig:side:b}
\end{minipage}
\end{figure}
插入占据双列的图片
\begin{figure*}
\centering
\subfigure[XGB]{
\includegraphics[width=5cm]{number_of_classes_0.pdf}}
\subfigure[DT]{
\includegraphics[width=5cm]{number_of_classes_1.pdf}}
\subfigure[LR1]{
\includegraphics[width=5cm]{number_of_classes_2.pdf}}
\subfigure[LR2]{
\includegraphics[width=4cm]{number_of_classes_3.pdf}}
\subfigure[SVC]{
\includegraphics[width=4cm]{number_of_classes_4.pdf}}
\subfigure[DNN]{
\includegraphics[width=4cm]{number_of_classes_5.pdf}}
\subfigure[RF]{
\includegraphics[width=4cm]{number_of_classes_6.pdf}}
\caption{MainfigureCaption}
\end{figure*}
效果:
一行两个Figure
\begin{figure}[!t]
\centering
\begin{minipage}[t]{0.49\linewidth}
\subfloat[subfig figure title]{
\includegraphics[width=1.25in]{figs/roc_cifar10.jpg} }
\subfloat[subfig figure title]{
\includegraphics[width=1.25in]{figs/boxplot_cifar10.jpg} }
\caption{The ROC curve and the distribution of fingerprint detection rate of different suspect models on CIFAR-10.}
\label{fig_6}
\end{minipage}
\begin{minipage}[t]{0.49\linewidth}
\subfloat[subfig figure title]{
\includegraphics[width=1.25in]{figs/fine-tune_cifar100.jpg}}
\subfloat[subfig figure title]{
\includegraphics[width=1.25in]{figs/fine-tune_ImageNet.jpg}}
\caption{title}
\label{fig_6}
\end{minipage}
\end{figure}
文字环绕
有时候单列的排版,图片过小,多出来的空白会显得很浪费,因此可以用以下指令设置文字环绕:
\usepackage{wrapfig} %需要先导入这个包
\begin{wrapfigure}{r}{0.6\textwidth}
\centering
\begin{subfigure}{0.49\linewidth}
\centering
\includegraphics[width=1.4in]{figs/Fig1a.jpg}
\caption{Single-point Fingerprinting} \label{fig:Fig1:a}
\end{subfigure}
\begin{subfigure}{0.49\linewidth}
\centering
\includegraphics[width=1.4in]{figs/Fig1b.jpg}
\caption{Trajectory Fingerprinting} \label{fig:Fig1:b}
\end{subfigure}
\end{wrapfigure}
调整子图与子标题之间的距离
用这个函数: \setlength{\abovecaptionskip}{-8.pt}
\begin{figure}[t]
\centering
%\vspace{5pt}
\begin{subfigure}{0.49\linewidth}
\centering
\includegraphics[width=1.58in]{figs/Pruning_cifar100.jpg}
\setlength{\abovecaptionskip}{-8.pt}
\caption{CIFAR-100}
\end{subfigure}
\hspace{-2pt}
\begin{subfigure}{0.49\linewidth}
\centering
\includegraphics[width=1.58in]{figs/Pruning_tinyimagenet.jpg}
\setlength{\abovecaptionskip}{-8.pt}
\caption{Tiny-ImageNet}
\end{subfigure}
\caption{ABC}
\label{fig:fine-tuning}
\end{figure}
调整图与caption之间的间距
\begin{wrapfigure}{r}{0.6\textwidth}
\begin{subfigure}{0.47\linewidth}
\centering
\includegraphics[width=1.55in]{figs/roc_cifar10.jpg}
\label{Fig:roc_curve}
\end{subfigure}
\hspace{-2pt}
\begin{subfigure}{0.47\linewidth}
\centering
\includegraphics[width=1.55in]{figs/boxplot_cifar10.jpg}
\label{Fig:distribution_4}
\end{subfigure}
\vspace{-15pt} % 通过这个参数调整
\caption{xxxxxxxx}
\label{Fig:roc_cifar10}
\end{wrapfigure}
控制图、表的位置
首先需要引用这个包: \usepackage{stfloats}
,这个包很重要,不建议插入 \usepackage{stfloats}
这个包,容易出问题。
然后 在 \begin{figure*} 后面加入 [htbp] 或者 [H] 就行了(推荐后者):
- h Here - at the position in the text where the table environment appears.
- t Top - at the top of a text page.
- b Bottom - at the bottom of a text page.
- p Page of floats - on a separate float page, which is a page containing no text, only floats.
注意事项
有时候我们需要在双栏的文档中插入跨行的表格,例如实现下面的效果:
那么对应的位置参数应该是[hb],也就是 \begin{figure*}[hb]
进行开头。
公式
数学公式在文中的位置可分为两种: 行中公式和独立公式。
行中公式
毕达哥拉斯定理 \begin{math} x^{2}+y^{2}=z^{2} \end{math}又称勾股定理。
或
毕达哥拉斯定理 $ x^{2}+y^{2}=z^{2} $又称勾股定理。
以上两种效果是一样的。
独立公式
$$
v = v^{1}e_{1} + v^{2}e_{2} + v^{3}e_{3} = v^{i}e_{i}, i = 1,2,3
$$
或
\begin{equation}
v = v^{1}e_{1} + v^{2}e_{2} + v^{3}e_{3} = v^{i}e_{i}, i = 1,2,3
\end{equation}
注意下面的这一种会自带公式编号
引用公式
\begin{equation}\label{eq:Pythagorean theorem}
x^{2}+y^{2}=z^{2}
\end{equation}
公式\ref{eq:Pythagorean theorem}是毕达哥拉斯定理,在中国又称勾股定理。%这里引用了
公式中插入中文
使用\mbox{}可在数学公式中插入中文。
$$
\mbox{例如:} x_{1}, x_{2}, \cdots, x_{N}
$$
可以换行的公式
\begin{equation}
\begin{aligned}
&\mathbb{E}_{ (\mathbf{x}^{i},y^{i})\sim{D_{train}}} [Uncertainty(f,\mathbf{x})] >\\
&\mathbb{E}_{ (\mathbf{x}^{i},y^{i})\sim{D_{test}}} [Uncertainty(f,\mathbf{x})]
\notag % 取消自动编号
\end{aligned}
\end{equation}
效果:
公式对齐
为了让第一行和第二行的公式对齐,我们使用&来对齐每一行的公式:
\begin{equation}
\begin{aligned}
sum &= a+b+c+d \\
sub &= a-b
\end{aligned}
\end{equation}
效果:
页脚注释
在正文中添加页脚注释的命令是:\footnote, 例如:
正文内容\footnote{注释内容}
也可以使用\footnotemark和\footnotetext 添加页脚注释,例如:
在这里添加页脚注释角标\footnotemark
%% ...
在这里设置注释内容\footnotetext{注释内容}
枚举
先加载宏包:
\usepackage{enumitem}
有很多款式,随意选择:
\begin{enumerate}[label=(\alph*)]
\item an apple
\item a banana
\item a carrot
\item a durian
\end{enumerate}
\begin{enumerate}[label=(\Alph*)] % 大写
\item an apple
\item a banana
\item a carrot
\item a durian
\end{enumerate}
\begin{enumerate}[label=(\roman*)] %罗马字体
\item an apple
\item a banana
\item a carrot
\item a durian
\end{enumerate}
字体与字号
可以添加在 \begin{table}后面,控制整个表格的字体。
Latex的字体由小到大分别为
\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
例如
如果在文档局部微调某些字句的字体大小:
{\tiny Hello}\\
{\scriptsize Hello}\\
{\footnotesize Hello}\\
{\small Hello}\\
{\normalsize Hello}\\
{\large Hello}\\
{\Large Hello}\\
{\LARGE Hello}\\
{\huge Hello}\\
{\Huge Hello}\\
如果需要在大范围调整,可使用\begin{}和\end{}命令。 例如:
\begin{footnotesize}
The package uses new font size other than default size.
\end{footnotesize}
Latex字体大小一般以pt做单位,pt是point的简写。
Latex文档字体大小的默认值\normalsize 是 10 points。\documentclass命令可以在导言区修改字体大小默认值,例如:
\documentclass[12pt, letterpaper]{article}
中文排版通常使用字号,例如:五号字,六号字等。 字号与pt的关系如下所列:
\begin{tabular}{lll}
\hline
七号 & 5.25pt & 1.845mm \\
六号 & 7.875pt & 2.768mm \\
小五号 & 9pt & 3.163mm \\
五号 & 10.5pt & 3.69mm \\
小四号 & 12pt & 4.2175mm \\
四号 & 13.75pt & 4.83mm \\
三号 & 15.75pt & 5.53mm \\
二号 & 21pt & 7.38mm \\
一号 & 27.5pt & 9.48mm \\
小初号 & 36pt & 12.65mm \\
初号 & 42pt & 14.76mm \\
\hline
\end{tabular}
或者直接自己根据pt定义字体大小:
\fontsize{20pt}{24pt}百度
居中标题
{\centering\section*{Additional Information}}
如果不可以的话就换成下面的指令:
\section*{\centering{Additional Information}}
参考文献
有时候期刊/会议下载下来的压缩包里没有 bst 文件,就会出现报错。可以用以下两个指令解决:
\bibliographystyle{unsrt} %这种是有序号的引用
\bibliography{mybib}
对应下面的样子:
\bibliographystyle{unsrtnat} %这种是无序号的引用
\bibliography{mybib}
对应下面的样子:
参考:https://blog.csdn.net/cocoonyang/article/details/78036326
https://blog.csdn.net/guifeng93/article/details/81035335
https://www.cnblogs.com/veagau/articles/11733769.html