Latex的安装与使用

环境安装

环境安装分两步:(1)安装 Tex live; (2)安装IDE:Lex Studio。其中Tex live是是Latex的一个发行版本,尽管Tex live本身带有编辑器,但是不好用,Lex Studio弥补了这一缺点,并且提供非常友好的界面,非常便于文档编辑和管理。

Tex的下载与安装

下载链接:l链接 , 具体下载流程参考:链接,下载完成后得到 texlive.iso镜像文件,然后进行安装。

Tex Studio的安装

下载链接:链接,下载完成后得到应用程序texstudio-x.xx.xx-win-qt5,进行安装即可。安装完成后启动tex Studio.
简单配置
(1)设置行号:Options->Configure Tex Studio->Adv. Editor-> Show Line Numbers->选中All line numbers选项。
注:首先应当勾选Show adv. options,然后才能看到Adv. Editor这一栏。
(2) 改为中文界面:Options—> Configure Texstudio —> General—> Language—> zh_CN。

Latex 编译原理

TeX 将输入的源代码变成最终输出的排版结果经历一下几个步骤:
(1) token scanning(记号扫描): TeX 将最初读入源代码中的字符转化为“记号”的过程。字母等普通字符是记号,以 \ 开头的命令(或者叫“控制序列”,control sequence)也是记号。
(2) macro expansion(宏展开): 将 LaTeX 格式的命令、宏包中的命令、用户自定义的命令等展开,直到剩下需要 TeX 直接处理的原始命令(primitives)和字符等记号。在 TeX 中能展开的不仅是宏,一些原始命令也能够展开,如将数字输出为罗马数字格式的原始命令 \romannumeral。
(3) primitive interpretation: 将前两部得到的各种记号转化为排版的“原料”,遇到字符记号则输出字符,遇到构造盒子的命令则输出盒子,遇到一些参数赋值的命令则改变一些状态,等等。每个命令都起到什么作用,在 TeXbook 24-26 章有总结,不过想看懂那一部分,基本上要把 TeXbook 或者 TeX by topic 完整啃一遍。源代码经过前三步的“消化”,生成的排版“原料”以列表的形式组织,根部为一个垂直列表,粗略来讲,包括文字段落、公式、图表盒子等内容;文字段落为一个水平列表;公式则由数学列表的形式组织。在进行下一步之前,数学列表会转化为水平列表,怎么转化的,细节在 TeXbook 附录 G,当然一上来不见得有多少人啃得动。
(4) line breaking: 将水平列表根据给定的宽度断行,生成从上到下排布的一系列盒子。由(不那么)著名的 Knuth-Plass 算法实现。
(5) page breaking: 一页内容从上到下填满,则进行断页操作。这一个步骤可以被利用起来,制造一些特殊的中断,从而实现诸如 LaTeX 处理浮动体之类的操作。
(6) page building: 将前两步生成的页面盒子加上页眉页脚等内容,打包生成最终的页面,所有的字符、图像等排版元素的位置和大小固化在这个页面上。
(7) 将上一个步骤中生成的页面写入输出格式,如 DVI 或 PDF。

在编译的过程中会产生一些中间文件加粗样式
(1) *.aux: 引用标记记录文件,用于再次编译时生成参考文献和超链接等。
(2) *.bbl: 由BiBTeX编辑.bib后创建的文献文件,再次编译时带入源文件生成文献列表。
(3) *.log: 编译过程记录文件,记录编译时出现的提示、警告和错误信息。
参考: https://www.zhihu.com/question/327762196

使用

简单使用

从模板开始编辑:首先准备好模板,例如IEEE Trans的模板,下载链接,然后File-> Open->选中要导入的文件->打开。
编译:选中Latex源文件(**.tex),然后点击 “绿色的右向三角形” 按钮编译,编译过程中会产生一些中间文件(原理中详述),编译成功会得到pdf文件(该文件与latex文件在同一目录),可用Adobe Acrobat打开,也可以点击 “放大镜” 按钮直接在内嵌界面中直接显示生成的pdf文件内容。
latex文件介绍: latex源文件的结构类似于超文本标记语言HTML,功能更为强大,不再赘述,关于latex文件的介绍详见 链接。并且提供各种各样的包,可以按照类似python的方式进行调用,从而可以轻松完成各种样式的排版。

配置语法检查功能

Options -> Configure TexStudio -> Language checking -> Default language:选择en_US.在这里插入图片描述

清理编译过程中生成的辅助文件

Tools -> Clear auxiliary files,

数学公式的编辑

各种数学公式符号对应的标记参照:链接;
公示的引用:引用相应的标记即可,例如:\ref{Eq1};
示例一:单个公式

\begin{equation} \label{Eq1}
\setlength\abovedisplayskip{1pt}
{\rm MIC}(x,y)=\mathop{\max}_{a \cdot b < N^{\alpha}} I_{a,b}(x,y)/log_{2} \mathop{\max}(a,b)
\setlength\belowdisplayskip{1pt}
\end{equation}

示例二:公式组

\begin{eqnarray}
\hat{\phi}, \hat{\varphi}=\mathop{\arg\min}_{\phi, \varphi}l(\phi, \varphi, \hat{\pi}),  \label{Eq3} \\
\hat{\pi}=\mathop{\arg\max}_{\pi}l(\hat{\phi},\hat{\varphi},\pi), \label{Eq4}
\end{eqnarray}

Latex公式的压缩

  1. 缩小公式内部的空隙宽度: 通过命令"\!"压缩公式中字符之间的间距;
  2. 缩小公式上下的空隙高度: 通过命令“\setlength\abovedisplayskip{3pt}” 和 “\setlength\belowdisplayskip{3pt}”来分别设置公式上和下的空隙高度;
  3. 将公式缩小为行内形式: 二项式系数、矩阵、累加缩小为行内形式,例:
\begin{eqnarray*}
  \dbinom{a}{b}\qquad\begin{pmatrix}a&b\\c&d\end{pmatrix}\qquad\sum_{k=1}^n k^2\\
  \tbinom{a}{b}\qquad\bigl(\begin{smallmatrix}a&b\\c&d\end{smallmatrix}\bigr)\qquad\begin{matrix}\sum_{k=1}^n k^2\end{matrix}
\end{eqnarray*}

表的编辑

表格常用的包:

\usepackage{threeparttable}
\usepackage{makecell}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{array} 
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{float}

几个需要注意的问题:

  1. 调节表格行间距:\begin{spacing}{1.1}
  2. 表格缩放:\resizebox{1.0\hsize}{!}{ xxxtable content xxx},该标记在表格超出页面时非常管用。
  3. 表格脚注:\begin{tablenotes} \footnotesize \item[1] xxxx \item[2] xxxx. \end{tablenotes}
  4. 单/双栏表格:\begin{table}为单栏表,\begin{table*}为跨栏表
    其中每个item对应一个脚注;
    5.表格位置控制:{table}有若干可选参数 [!htbp]
    h代表here,将表格排在当前文字位置
    t 表示将表格放在下一页的 top (页首)
    b 表示将表格放在当前页的 bottom (底部)
    !表示忽略美观因素,尽可能按照参数指定的方式来处理表格浮动位置。
    表格将会按照所给参数,依次尝试按照每个参数进行排版,当无法排版时,将会按照下一个参数
    5.调整表格距下文的间距:
    \begin{table}中添加如下命令:
\vspace{-1em}

示例一

\begin{table}[h]
	\begin{center}
		\begin{spacing}{1.1}
			\caption{Network configurations of RDAE.}\label{table1}
			\resizebox{1.0\hsize}{!}{
				%\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
				\begin{tabular}{ccccccccc}
					%\hline
					\toprule
					\multirow{1}{*}{\makecell[{}{p{1.1cm}}]{\textbf{Module}}} & \multirow{1}{*}{\makecell[{}{p{1.1cm}}]{\textbf{Block}}} & 
					\multirow{1}{*}{\makecell[{}{p{1.5cm}}]{\textbf{Layer}}} & 
					\multirow{1}{*}{\makecell[{}{p{1.2cm}}]{\textbf{Kernel$^1$}}} &
					\multirow{1}{*}{\makecell[{}{p{1.5cm}}]{\textbf{Output$^1$}}} &
					\multirow{1}{*}{\makecell[{}{p{1.5cm}}]{\textbf{Stride/Factor}}} &
					\multirow{1}{*}{\makecell[{}{p{1.2cm}}]{\textbf{Pad.}}} &
					\multirow{1}{*}{\makecell[{}{p{1.2cm}}]{\textbf{Activ.}}} &
					\multirow{1}{*}{\makecell[{}{p{1.5cm}}]{\textbf{Drop rate.}}} \\
					%\hline
					\midrule
					\multirow{25}{*}{\makecell[{24}{p{1.2cm}}]{Conv. AE}} &
					\multirow{1}{*}{\makecell[{}{p{2cm}}]{ —— }} & 
					Input & —— &  ($L$,1)& —— &  ——  & ——  & —— \\
					\cline{2-9}
					& \multirow{2}{*}{\makecell[{}{p{1.0cm}}]{block-1}} & 
					Conv1D & (15, $b$) & ($L$, $b$) &  1/  &  same & ReLU & —— \\
					\cline{3-9}
					&  & Conv1D  & (15, $b$) & ($L$/5, $b$) & 5/ & same & ReLU & —— \\
					\cline{2-9}
					& \multirow{3}{*}{\makecell[{}{p{1.0cm}}]{block-2}} & 
					Conv1D & (15, 2$b$) & ($L$/5, $b$) & 1/ & same & ReLU & —— \\
					\cline{3-9}
					&  & Conv1D  & (15, 2$b$) & ($L$/25, 2$b$) & 5/ & same & ReLU & —— \\
					\cline{3-9}
					&  & Dropout  & —— & —— &  —— & —— & —— & 0.1 \\
					\cline{2-9}
					& \multirow{3}{*}{\makecell[{}{p{1.0cm}}]{block-3}} & 
					Conv1D &  (15, 4$b$) & ($L$/25, 4$b$) &  1/ & same & ReLU & ——\\
					\cline{3-9}
					&  & Conv1D  &  (15, 4$b$) & ($L$/50, 4$b$) & 2/ & same & ReLU & ——\\
					\cline{3-9}
					&  & Dropout  & —— & —— & —— & —— & —— & 0.1\\
					\cline{2-9}
					& \multirow{3}{*}{\makecell[{}{p{1.0cm}}]{block-4}} & 
					Flatten & —— & $L$ x 32/50 & —— & —— & —— & —— \\
					\cline{3-9}
					&  & Dropout  & —— & —— & —— & —— & —— & 0.1\\
					\cline{3-9}
					&  & Dense  & —— & 32 & —— & —— & ReLU & —— \\
					\cline{2-9}
					& \multirow{1}{*}{\makecell[{}{p{1.0cm}}]{——}} & 
					Dense & —— & $latent\_dim$ & —— &  —— & None & —— \\
					\cline{2-9}
					& \multirow{4}{*}{\makecell[{}{p{1.1cm}}]{block-4'}} & 
					Dense & —— & 32 & —— & —— & ReLU & —— \\
					\cline{3-9}
					&  & Dense  & —— & $L$x32/50 & —— & —— & ReLU & —— \\
					\cline{3-9}
					&  & Dropout  & —— & —— & —— & —— & —— & 0.1 \\
					\cline{3-9}
					&  & Reshape  & —— & ($L$/50, 4$b$) & —— & —— & ——  & —— \\
					\cline{2-9}
					& \multirow{3}{*}{\makecell[{}{p{1.1cm}}]{block-3'}} & 
					Conv1D & (15,4$b$)  & ($L$/50, 4$b$) & 1/ &  same & ReLU & —— \\
					\cline{3-9}
					&  & UpSample  & —— &  ($L$/25, 4$b$) & /2 & —— & —— & —— \\
					\cline{3-9}
					&  & Dropout  & —— & —— & —— & —— & —— & 0.1 \\
					\cline{2-9}
					& \multirow{3}{*}{\makecell[{}{p{1.1cm}}]{block-2'}} & 
					Conv1D & (15, 2$b$) & ($L$/25, 2$b$) & 1/ & same & ReLU & —— \\
					\cline{3-9}
					&  & UpSample  & —— & ($L$/5, 2$b$) & /5 &  —— & —— & —— \\
					\cline{3-9}
					&  & Dropout  & —— & —— & —— &  —— &  ——  & 0.1 \\
					\cline{2-9}
					& \multirow{3}{*}{\makecell[{}{p{1.1cm}}]{block-1'}} & 
					Conv1D & (15, $b$) & ($L$/5, $b$)  & 1/ & same & ReLU & —— \\
					\cline{3-9}
					&  & UpSample  & —— & ($L$, $b$) & /5 & —— & —— & —— \\
					\cline{3-9}
					&  & Conv1D  & (15, 1) & ($L$,1) & 1/ & same & None & —— \\
					\hline
					\multirow{5}{*}{\makecell[{}{p{1.2cm}}]{Domain cls.}} & \multirow{5}{*}{\makecell[{}{p{1.0cm}}]{ ——$^2$}}
					& Dense & —— & $latent\_dim$  &  —— & —— & None & —— \\
					\cline{3-9}
					&  & BatchNorm  & —— & —— &  —— & —— & ReLU & —— \\
					\cline{3-9}
					&  & Dense  & —— & $latent\_dim$ & ——  & —— & None & —— \\
					\cline{3-9}
					&  & BatchNorm & —— & —— & —— & —— & ReLU & —— \\
					\cline{3-9}
					&  & Dense  & —— & #records  & —— & —— & None & —— \\
					%\hline
					\bottomrule
				\end{tabular}
			}
			\begin{tablenotes}
			\footnotesize
			\item[1] $^1$$(a, b)$, $a$ denotes kernel size (in ‘Kernel’ column) or output dimension (in ‘Output’ column), and $b$ denotes the number of channels.
			\item[2] $^2$'——' denotes the corresponding attribute is not applicable to the layer, ‘None’ denotes linear activation.
			\end{tablenotes}
		\end{spacing}
	\end{center}
\end{table}

图的编辑

常用包:

\usepackage{subfigure}
\usepackage{graphicx}

几点说明:

  1. 多张图的横排与竖排:同一个\subfigure下每个\includegraphics对应的图之间是竖排的,不同\subfigure对应的图之间是横排的;
    特别注意:每个\subfigure包含的图(可以是一张或者多张)拥有一个子标记label,例如:(a);
  2. 调整图大小:可通过\includegraphics[scale=.55]缩放图片,或者通过\includegraphics[width=1.5in,height=1.0in]直接设置图片的高和宽;
  3. 单/双栏图:\begin{figure}为单栏图,\begin{figure*}为跨栏图;
  4. 调整图距上下文的空白间距
    如下两行命令放在\begin{figure}下面:
\setlength{\abovecaptionskip}{2pt} 
\setlength{\belowcaptionskip}{-2pt}

示例一

\begin{figure*}
	\centering
	\subfigure[]{
		\label{Fig:5-1-1}
		\begin{minipage}{0.25\linewidth}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/filter-ppg-pos-0-0-31}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/filter-ppg-pos-1-421-37}
		\end{minipage} 
	}%
	\subfigure[]{
		\label{Fig:5-1-2}
		\begin{minipage}{0.25\linewidth}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/filter-abp-pos-0-87-36}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/filter-abp-pos-0-1140-19}
		\end{minipage} 
	}%
	\subfigure[]{
		\label{Fig:5-1-3}
		\begin{minipage}{0.25\linewidth}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/abp-low-quality2-sql-0-0-0-pos-0-310-32}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/abp-low-quality2-sql-0-0-0-pos-0-472-30}
		\end{minipage} \\
	
		\label{Fig:5-1-4}
		\begin{minipage}{0.25\linewidth}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/abp-low-quality2-sql-0-0-0-pos-0-516-7}
			\includegraphics[width=1.5in,height=1.0in]{figs/preprocess/abp-low-quality2-sql-0-0-0-pos-0-99-5}
		\end{minipage} 
	} 
	\caption{Preprocess results and excluded abnormal segments. (a) PPG signal; (b) ABP signal; (c)excluded abnormal ABP segments.} \label{Fig:5}
\end{figure*}

算法伪码排版

常用包:

\usepackage{algorithm}  
%\usepackage{algorithmic}  % this will cause row number error in algorithm template.
\usepackage{algpseudocode}  
\usepackage{amsmath}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm  
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm 

其中 algorithmicalgorithmicx两个包的标记有很多相似但又不同的地方,这两个包包含的标记见:链接, 实际使用中建议只是用其中一个,不要混用。

示例一(基于algorithmic包)

\begin{algorithm}[h]
	\setstretch{0.9}
	\caption{RDAE}
	\label{alg::RDAE}
	
	\begin{algorithmic}[1]
		\Require
		$D$: data, \{($x^{i}$, $y^{i}$)\};
		$E_{\phi}$: encoder;
		$D_{\varphi}$: decoder;
		$D_{\pi}$: domain classifier;
		$B$: batchsize;
		$K$: number of inner iterations;
		$maxEpoch$: maximum number of epoches;
		$\alpha$: learning rate;
		$\lambda$: weight factor
		\Ensure
		optimal model parameterized with $\varphi$ and $\phi$
		\State $t=0$;
		\State initialize parameters $\phi$, $\varphi$ and $\pi$;
		
		\Repeat 
		\State $t \leftarrow t+1$;
		\For{each $k \in [1,K]$}  
		\State sample $\{(x^{i}, y^{i})\}^{B}_{i=1}$ from dataset $D$; 
		\State compute latent code: $z^{i}=E_{\phi} (x^{i})$ for $i \in {1,2,...,B}$; 
		\State compute output of domain classifier: $\hat{d}_{x^{i}}=D_{\pi} (z^{i})$ for $i \in {1,2,...,B}$; 
		\State compute gradient w.r.t $\pi$: $g_{\pi} \leftarrow \bigtriangledown{\pi} \frac{1}{B} \sum_{i=1}^{B} L_{d} (\hat{d}_{x^{i}}, d_{x^{i}})$; 
		\State update domain classifier: $\pi \leftarrow \pi - \alpha \cdot g_{\pi}$; 
		\EndFor
		
		\State sample $\{(x^{i}, y^{i})\}^{B}_{i=1}$ fr{\tiny \label{key}}om dataset $D$; 
		\State compute latent code: $z^{i}=E_{\phi} (x^{i})$ for $i \in {1,2,...,B}$;
		\State compute output of domain classifier: $\hat{d}_{x^{i}}=D_{\pi} (z^{i})$ for $i \in {1,2,...,B}$; 
		\State compute output of decoder: $\hat{y}^{i}=D_{\varphi}(z^{i})$ for $i \in {1,2,...,B}$; 
		\State compute gradient w.r.t $\phi$: $g_{\phi} \leftarrow \bigtriangledown{\phi} \frac{1}{B} \sum_{i=1}^{B} {L_{r}(\hat{y}^{i}, y^{i}) - \lambda \cdot L_{d}(\hat{d}_{x^{i}}, d_{x^{i}})}$; 
		\State update encoder: $\phi \leftarrow \phi - \alpha \cdot g_{\phi}$; 
		\State compute gradient w.r.t $\varphi$: $g_{\varphi} \leftarrow \bigtriangledown{\varphi} \frac{1}{B} \sum_{i=1}^{B} L_{r}(\hat{y}^{i}, y^{i})$; 
		\State update decoder: $\varphi \leftarrow \varphi - \alpha \cdot g_{\varphi}$; 
		\Until {converged \textbf{or}  $t > maxEpoch$} 
	\end{algorithmic}
\end{algorithm} 

更多示例参见: 链接1, 链接2

参考文献管理

Latex中,一般参考文献的引用全部位于**.bib文件中,可以从一下两个途径获取latex样式的引用格式:
(1)research Gate: 找到文献后->cite->Bib tex -> copy-> past;
(2)google: 找到文献后->cite->Bib tex -> copy-> past;
令:将arXiv引用转化为Bibtex引用样式,可通过在线转换工具:链接, 只需输入paper的ID即可。
特别注意:更新完bib文件,需要编译两次后,正文中才能正确显示引用,否则在引用位置处会出现??。

当然还有一种方式是在tex文件中使用 begin{thebibliography}{00}, 然后通过\bibitem 来直接插入参考文献,这种方式不需要bib文件。详情参考https://blog.csdn.net/cdpxc/article/details/119784556

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

MasterQKK 被注册

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

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

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

打赏作者

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

抵扣说明:

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

余额充值