[论文工具] LaTeX论文撰写常见用法及实战技巧归纳(持续更新)

您所在的位置:网站首页 写作技巧知识点归纳 [论文工具] LaTeX论文撰写常见用法及实战技巧归纳(持续更新)

[论文工具] LaTeX论文撰写常见用法及实战技巧归纳(持续更新)

2024-07-01 01:15| 来源: 网络整理| 查看: 265

祝大家中秋国庆双节快乐! 回过头来,我们在编程过程中,经常会遇到各种各样的问题。然而,很多问题都无法解决,网上夹杂着各种冗余的回答,也缺乏系统的实战技巧归纳。为更好地从事科学研究和编程学习,后续将总结各类常见实战技巧,希望对您有所帮助。

本文主要介绍LaTeX论文撰写的常见用法和实战技巧总结,包括论文的基本结构、算法、图片、表格、公式、特殊符号、参考文献、序号等方法。全文将持续更新,一方面作为自己的学习笔记,另一方面希望能帮助初学者解决实际问题,且看且珍惜!

文章目录 基本论文结构什么是LaTeX基本结构篇章结构 算法algorithmalgorithm2e 图片基本用法双栏显示双图显示 表格基本用法含注释的表格复杂表格合并multirow解决自动换行 公式特殊符号圆圈数字半圆勾叉纸牌 参考文献序号总结

基本论文结构 什么是LaTeX

LaTeX是一种基于ΤΕΧ的排版系统,由美国计算机学家莱斯利·兰伯特在20世纪80年代初期开发,利用这种格式,即使使用者没有排版和程序设计的知识也可以充分发挥由TeX所提供的强大功能,能在几天、甚至几小时内生成很多具有书籍质量的印刷品。对于生成复杂表格和数学公式,这一点表现得尤为突出。因此它非常适用于生成高印刷质量的科技和数学类文档。

LaTeX的工作方式类似网页,它们都是由源文件(.tex or .html)经由引擎(TeX or browser)渲染产生最终效果,从而得到PDF文件或生成页面。两者极其神似,包括语法规则与工作方式。

在这里插入图片描述

官方下载地址如下:

Tex Live下载地址:http://www.tug.org/texlive/清华大学镜像地址:https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/Tex studio下载地址:http://www.texstudio.org/

强烈推荐大家直接下载LaTex模块进行修改,这篇文章更多是告诉大家基本语法,安装过程请大家下来去尝试,希望对您有所帮助!

基本结构

LaTeX文档分为导言区和正文区(文稿区),在导言区我们可以使用documentclass命令引入一个文档类,也可以有book类、report类、letter类,其中百分号表示注释,不参与文档编译且不作为输出。在正文区用begin和end输入一个环境,如下图所示:

在这里插入图片描述

接着将环境的名称设置为document,一个LaTeX文件有且只能有一个document文件,添加正文内容再编译文档。

在这里插入图片描述

导言区主要用于全局设置,比如文档标题、作者、日期,再通过maketitle显示标题。

% 导言区 \documentclass{article} \title{My First Document} \author{Eastmount} \date{\today} % 正文区 \begin{document} \maketitle Hello World! \end{document}

显示如下图所示:

在这里插入图片描述

篇章结构

学术论文通常包括两种结构,如下图所示,左边表示理论型,右边表示实验型。

在这里插入图片描述

在LaTeX中我们可以通过section定义小结,也可以用subsection定义子小结。同时更推荐大家下载IEEE结构进行修改,后面我也会讲到。

\section{Section title}\label{sec:mysection}\subsection{title}\subsubsection{title}\section*{} unnumbered section\appendix

举个示例:

% 导言区 \documentclass{article} \usepackage{ctex} \title{My First Document} \author{Eastmount} \date{\today} % 正文区 \begin{document} \maketitle % 构建文章小结 \section{Introduction} \section{Related Work} \section{System Model} \section{Mathematics and algorithms} \section{Experiments} \subsection{Datasets} \subsubsection{实验条件} \subsubsection{评价指标} \subsection{Results} \section{Acknowledgment} \end{document}

输出结果如下图所示:

在这里插入图片描述

算法

通常采用两种方法进行算法的编写,包括:

使用algorithm、algorithmic宏包使用algorithm2e宏包 algorithm

导入包:

\usepackage{algorithm} \usepackage{algorithmic}

算法代码:

\begin{algorithm}[!ht] \caption{Feature extraction based on abstract syntax tree.} \begin{algorithmic}[1] \REQUIRE {$X=\left\{x_1,x_2,...,x_n\right\}$, where $x_i$ is the $i^{th}$ PowerShell script.} \ENSURE {$V^{(ast)}=\left\{v_1,v_2,...,v_n\right\}$, where $v_i$ is the $i^{th}$ sequence vector generated by AST-based feature extraction method (i.e., AST2Vec).} \STATE $V^{(ast)} \leftarrow \emptyset$ , $S \leftarrow \emptyset$, $F \leftarrow \emptyset$, $W \leftarrow \emptyset$ \FOR{$i \leftarrow 1$ {\bf to} $n$} \STATE $t_i = ExtractAstSequences( x_i )$ \STATE $s_i = PostorderTraversal( t_i )$ \STATE $S.append( s_i )$ \ENDFOR \STATE $F = BuildFeatureSetFromAst(S) $ \STATE $//$ Count all distinct features of AST sequences. \FOR{each $f_k \in F$} \STATE $w_k = CalculateWordVectors( f_k )$ \STATE $W.append( w_k )$ \ENDFOR \STATE $//$ Calculate word vectors for each AST node. \FOR{each $s_i \in S$} \STATE $v_i = GenerateAstEmbedding( s_i )$ \STATE $V^{(ast)}.append( v_i )$ \ENDFOR \STATE {\bf return} {$V^{(ast)}$} \end{algorithmic} \label{algorithm1} \end{algorithm}

运行结果如下图所示:

在这里插入图片描述

algorithm2e

导入包:

\usepackage{algorithm} \usepackage[algo2e]{algorithm2e}

算法代码:

\begin{algorithm}[!ht] \caption{Feature extraction based on abstract syntax tree.} \label{algorithm1} \SetAlgoLined \SetKwInOut{Input}{Input} \SetKwInOut{Output}{Output} \Input{$X=\left\{x_1,x_2,...,x_n\right\}$, where $x_i$ is the $i^{th}$ PowerShell script.} \Output{$V^{(ast)}=\left\{v_1,v_2,...,v_n\right\}$, where $v_i$ is the $i^{th}$ sequence vector generated by AST-based feature extraction method (i.e., AST2Vec).} Initialization: $V^{(ast)} \leftarrow \emptyset$ , $S \leftarrow \emptyset$, $F \leftarrow \emptyset$, $W \leftarrow \emptyset$ \For{$i \leftarrow 1$ \KwTo $n$}{ $t_i = ExtractAstSequences( x_i )$ $s_i = PostorderTraversal( t_i )$ $S.append( s_i )$ } $F = BuildFeatureSetFromAst(S) $ \tcc{Count all distinct features of AST sequences} \For{$f_k \in F$}{ $w_k = CalculateWordVectors( f_k )$ $W.append( w_k )$ } \tcc{Calculate word vectors for each AST node} \For{$s_i \in S$}{ $v_i = GenerateAstEmbedding( s_i )$ $V^{(ast)}.append( v_i )$ } \Return{$V^{(ast)}$} \end{algorithm}

运行结果如下图所示:

在这里插入图片描述

图片 基本用法

在LaTeX中插入图片的基本语法如下:

导言区插入:\usepackage{graphicx}语法:\includegraphics[ < 选项 > ] { < 文件名 > }格式:EPS、PDF、PNG、JPEG、BMP

在这里插入图片描述

下面举例说明:

% 导言区 \documentclass{article} \usepackage{ctex} \usepackage{graphicx} % 指定图片在当前目录下figures目录下 \graphicspath{{figures/}} % 正文区 \begin{document} % 插入图片 \includegraphics{fig1} % 缩放比例 \includegraphics[scale=0.5]{fig1} % 固定图像高度 \includegraphics[height=2cm]{fig1.png} % 固定图像宽度 \includegraphics[width=2cm]{fig1.png} % 图像高度和宽度基于 \includegraphics[height=0.2\textheight]{fig1.png} \includegraphics[width=0.2\textwidth]{fig1.png} % 指定多个参数 \includegraphics[angle=-45,width=0.5\textwidth]{fig1.png} \end{document}

显示结果如下图所示,scale=0.5是将图片大小缩小为真实大小的一半,[width=0.2\textwidth] 将图形缩放到文本的0.2倍。

在这里插入图片描述

双栏显示

注意,在论文中通常会遇到要横跨两栏的应用场景,此时我们需要这样设置:

\begin{figure*}\end{figure*} \usepackage{stfloats} \begin{figure*}[ht] \centering \includegraphics[width=0.8\textwidth]{4.eps} \caption{BER performance of original OFDM system and different companding schemes over AWGN channel (QPSK).} \label{fig8} \end{figure*}

上面代码中,figure* 表示跨双栏,htbp表示的意思是latex会尽量满足排在前面的浮动格式,就是h-t-b-p这个顺序,让排版的效果尽量好。其中,h-here表示在此处,t-top表示在顶部,b-bottom表示底部,p-page表示在本页。为了防止跨页图片跑到最后一页,我们需要在导言区加入stfloats包,然后设置\begin{figure*}[ht] 即可。

h——放置在此处 t——放置在顶部 b——放置在底部 p——浮动放置 *——两栏放置

在这里插入图片描述

双图显示

第一种方式——调用minipage实现,也是最常见的方式。

\begin{figure*} \begin{minipage}[t]{0.48\linewidth} \centering \includegraphics[scale=0.30]{Figure-7.eps} \caption{The loss curve of different models.} \label{fig7} \end{minipage} \begin{minipage}[t]{0.48\linewidth} \centering \includegraphics[scale=0.30]{Figure-8.eps} \caption{The accuracy curve of different models.} \label{fig8} \end{minipage} \end{figure*}

显示效果如下图所示:

在这里插入图片描述

第二种方式——调用subfigure实现。

\usepackage{caption} \usepackage{subfigure} \begin{figure}[htbp] \centering %居中 \subfigure[name of the first figure] %第一张子图 { \begin{minipage}[t]{0.4\textwidth} \centering \includegraphics[scale=0.15]{fig2} \end{minipage} } \subfigure[name of the second figure] %第二张子图 { \begin{minipage}[t]{0.4\textwidth} \centering \includegraphics[scale=0.2]{fig3} \end{minipage} } \caption{name of the figure} %大图名称 \label{fig-1} %图片引用标记 \end{figure}

显示如下图所示:

在这里插入图片描述

第三种方法——调用宏包宏包subfig。使用subfig宏包提供的\subfloat命令,需要使用宏包\usepackage{graphicx}和\usepackage{subfig}。

\begin{figure}[!hb] \centering \subfloat[\label{fig:arm1}$Q^{*}$ values for arm 1]{\includegraphics[width=.5\linewidth]{1.eps}}% \subfloat[\label{fig:arm2}$Q^{*}$ values for arm 2]{\includegraphics[width=.5\linewidth]{1.eps}}\\ \subfloat[\label{fig:arm3}$Q^{*}$ values for arm 3]{\includegraphics[width=.8\linewidth]{1.eps}} \caption{$Q^{*}$ values for different arms.} \label{fig:arms} \end{figure}

显示如下图所示:

在这里插入图片描述

表格 基本用法

在LaTeX中使用tabular生成表格,插入时需要设置对齐方式(l-左对齐、c-居中对齐、r-右对齐),然后插入数据,其中&用于分割每列,\\用于换行。下面的代码展示常见的三线表。

\begin{table} \caption{Symbol Table} \centering \begin{tabular}{lll} \hline Symbol & Definition & Unitis\\ \noalign{\global\arrayrulewidth1pt}\hline\noalign{\global\arrayrulewidth0.4pt} \multicolumn{3}{c}{\textbf{Constants}}\\ $\lambda$ & Mean of Poisson distribution & unitless\\ $p_{slow}$ & Probability that a vehicle slows down randomly & unitless\\ \hline \end{tabular} \end{table}

显示如下图所示:

在这里插入图片描述

含注释的表格

在IEEE的LaTex模板里希望添加表格的注释,即说明表格字符的含义。具体流程如下:

使用\usepackage{threeparttable}\begin{tabular}后加上\begin{threeparttable},和\end{tabular}前加上\end{threeparttable}注释加在\begin{tablenotes} 和 \end{tablenotes}之间

导入扩展包如下所示:

\usepackage{threeparttable} \usepackage{float} \usepackage{bbding} \usepackage{pifont}

代码如下:

\begin{table*}[!ht] \centering \caption{Related work comparison.} \begin{threeparttable} \resizebox{\textwidth}{!}{ \begin{tabular}{ccccm{1.2cm}


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3