Latex大全

本文介绍了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…} 012abcxABCX,对比下\textbf{012…abcx…ABCX…} 012 … abcx … ABCX … \textbf{012…abcx…ABCX…} 012abcxABCX,好像效果一样!

斜粗体
语法 \boldsymbol{012…abc…ABC…\alpha \beta\gamma…} 012 … a b c x … A B C X … α β γ … \boldsymbol{012…abcx…ABCX…\alpha \beta\gamma…} 012abcxABCXαβγ

注意:
  1. 英文字母 “L” 的小写 “l” 很容易和1搞混,因此我们一般使用 \ell 来代替 l,效果: ℓ \ell
  2. 数域⽤\mathbb{R}( R \mathbb{R} R),\mathbb{Z}( Z \mathbb{Z} Z)。
  3. \boldsymbol{x} 组成的集合⽤\mathcal{X}( x ∈ X \boldsymbol{x} \in \mathcal{X} xX),a 组成的集合⽤ A( a ∈ A a \in A aA
  4. 公式中的 softmax,proj,enc 等,超过⼀个字⺟的变量或符号,要⽤正⽂字体,即写成 \textrm{softmax} 或 \textit{FFN}。
  5. 公式中的括号,要⽤\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)=(nrn)=Crn=Cnrn
矩阵
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

重音符号(向量符号)

在这里插入图片描述

希腊字母

在这里插入图片描述

二元关系

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

运算符

在这里插入图片描述

大运算符(积分求和)

在这里插入图片描述

箭头

在这里插入图片描述
在这里插入图片描述

定界符(括号)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
如何打出大定界符?:
在这里插入图片描述
\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科技论文,报告,软件文档等
IEEEtranIEEE 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{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]在方括号中修改。

  • 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.

表格字体大小

插入\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是限制列宽的右对齐。
在这里插入图片描述

设置表格宽度

需要用到 \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图

\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*}

效果:
在这里插入图片描述

公式

数学公式在文中的位置可分为两种: 行中公式独立公式

行中公式

毕达哥拉斯定理 \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}百度

参考:https://blog.csdn.net/cocoonyang/article/details/78036326
https://blog.csdn.net/guifeng93/article/details/81035335
https://www.cnblogs.com/veagau/articles/11733769.html

表格示例大全

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
LaTeX是一种排版系统,它通过使用一些命令和语法,可以将文档以高质量的方式排版出来。下面是一些常用的LaTeX命令大全: 1. 文档类命令:\documentclass{类别},定义文档的类型,如article, report, book等。 2. 宏包命令:\usepackage{宏包},引用宏包,增加功能,如graphicx(插入图片)、amsmath(数学公式)等。 3. 标题命令:\title{标题}、\author{作者}和\date{日期},定义文档的标题、作者和日期。 4. 开始命令:\begin{document},开始正文内容。 5. 结束命令:\end{document},结束文档。 6. 章节命令:\section{标题}、\subsection{标题}和\subsubsection{标题},定义章、节和子节的标题。 7. 列表命令:\begin{itemize}和\end{itemize},创建无序列表;\begin{enumerate}和\end{enumerate},创建有序列表。 8. 图片插入命令:\includegraphics{文件路径},插入图片。 9. 表格命令:\begin{tabular}和\end{tabular},创建表格。 10. 数学公式命令:\begin{equation}和\end{equation},创建行内数学公式。 11. 引用命令:\cite{引用标签},引用参考文献。 12. 脚注命令:\footnote{脚注内容},创建脚注。 13. 交叉引用命令:\label{标签名},给某个元素添加标签;\ref{标签名},引用标签。 14. 字体命令:\textbf{加粗},\textit{斜体},\underline{下划线}等,改变字体样式。 15. 段落命令:空行表示段落分隔,\par可以代替空行。 以上是一些常用的LaTeX命令,通过学习和运用它们,我们可以在LaTeX中编写高质量的文档。在实际使用过程中,还可以参考LaTeX手册或在线文档,了解更多命令和功能,以满足不同排版需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一起来学深度学习鸭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值