LaTeX外部模板(IEEEtrans)初次套用经历

时间:2024-03-22 18:17:11

 

最近对文档进行排版的过程中首次用到了LaTeX,所以在此将这个过程记录下来,希望对初次使用的同学有帮助。

首先说一下对Word和LaTeX的一个整体感受:Word在草稿阶段是比较方便易用的,可用来完成文档的编辑工作,但是最终在排版成某种固定格的话,不如LaTeX易用方便,因为使用Word模板的时候经常会碰到图片、表格跑来跑去,留下大段的空白,公式显示问题等,某些格式就是调不成想要的样子,而且针对不同的模板就必须要重新再调一次,这时候就显示出LaTeX的好处了,虽然LaTeX一开始不如Word简单明了,但是只要几种花个时间把LaTeX编辑文档的大致流程顺下来,就会发现用LaTeX编辑文档几乎不用花时间调整格式,你只要把内容填在该填的框架内,并且针对不同格式的模板,只需要很小的样式改动就可以,方便复用,因此,本教程就是以我自身的体验跟大家顺一下这个LaTeX的初次模板使用过程。

LaTeX安装

网上安装的教程很多,我选择的是texlive+texstudio,安装指南见Windows系统下latex:texlive2018和texstudio

LaTeX模板套用

一般来说,LaTeX主要用在论文提交,书籍排版过程中,提交论文的时候,人家会提供一个模板,要你按要求排版,在此我选择的是IEEEtrans模板,针对的是英文文档,不包含中文,可在https://ctan.org/pkg/ieeetran或在https://journals.ieeeauthorcenter.ieee.org/create-your-ieee-article/authoring-tools-and-templates/ieee-article-templates/templates-for-transactions/下载(WIN or MAC LaTeX2e Transactions Style File)并解压。

模板安装

将解压的文件里的CLS文件IEEEtran放在在texlive安装路径~\texmf-local\tex\latex下,并在cmd输入texhash刷新数据库。

LaTeX外部模板(IEEEtrans)初次套用经历

模板使用

新建自己的测试文件夹latex_test,将解压文件夹里的bare_jrnl拷贝到latex_test并重命名为test_main,其中bare_jrnl是IEEE transactions投稿使用的模板,并将IEEEtran也拷贝到该文件。

LaTeX外部模板(IEEEtrans)初次套用经历

在texlive中打开test_main,其中的一些大致框架都已经搭好了,只要替换相应的文字就可以了,如标题、摘要,正文,texlive中两个绿色三角的按钮分别是运行并显示FDF和编译。IEEEtrans的官方英文教程链接:https://pan.baidu.com/s/1umgb0Yzaw0OCVbJEATBzcA 
提取码:i9nc 
 

本教程源文件存放在链接:https://pan.baidu.com/s/1qCJDGqSGG_v0ozMzDVAnMg 
提取码:ie3s 

 

开头设置,包括文档类型,字号,所使用的工具包等

\documentclass[10pt,journal,final]{IEEEtran}%我们使用的是IEEEtran风格的外部模板,还有一些内置的article等,方括号的是参数,包括字号,期刊类型,所用模板是双列

%接下来我们在图片、表格、公式等的编辑中,需要用usepackage导入一些package,就类似于python或C++中包的import和include吧。
\usepackage{multirow} %关于表格
\usepackage{booktabs}
\usepackage{makecell}

\usepackage{cite}%参考文献
\usepackage{graphicx}%图片
\graphicspath{{./figures/}}%说明待加载的图片的路径,在后期图片加载的时候不用再写路径,直接用图片名称
  
\usepackage{amsmath}%公式
\interdisplaylinepenalty=2500

% 子图设置
\ifCLASSOPTIONcompsoc
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
\else
\usepackage[caption=false,font=footnotesize]{subfig}
\fi

% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}

正文开始,正文内容包含在

\begin{document} ...  \end{document}

之间,并把相应的文字填到对应的部分,如摘要,引言等,Section,subsection和subsubsection分别是一、二和三级标题,并展示list的应用,如下。

\begin{document}
%正文开始,把文字填到相应的部分
\title{learning LaTeX}
\author{Hong~Xiao  }

\maketitle
\begin{abstract}
As recently as last week, Trump was calling outside advisers to complain about Bolton, people familiar with the conversations said. 
\end{abstract}

\begin{IEEEkeywords}
latex
\end{IEEEkeywords}

\IEEEpeerreviewmaketitle


\section{Primary title}%一级标题
Washington (CNN)President Donald Trump has become irritated at an emerging impression his hawkish national security advisers are marching him closer to war with Iran despite his isolationist tendencies, according to people familiar with the matter.

%另起一段,回车,空一行
Instead, Trump is signaling his intent to speak with the Iranians as tensions rise in the Persian Gulf, and his national security team has taken steps they hope could facilitate a new diplomatic opening.

\subsection{The secondary title}%二级标题
The likelihood of such an opening appears slim. But Trump has raised concern with the heightened rhetoric, believing a large-scale military intervention with Iran would be devastating to him politically, people familiar with the situation said.

\subsubsection{The secondary title}%三级标题
 The President has told members of his team that starting a new conflict would amount to breaking his campaign promise to wind down foreign entanglements. And he's chafed at suggestions his aides, led by national security adviser John Bolton, are somehow leading him to war.

\subsection{show list}%列表展示
\begin{enumerate}[\IEEEsetlabelwidth{4)}]%4个条目
	\item AAAAAA.
	\item BBBBBBBBBBBB. 
	\item CCCCCCCCCC.
	\item DDDDDDDDDDDDDDDDDDDDDDD.
	
\end{enumerate}

图片写好路径之后,根据名称加载,图片存放在当前目录的figures文件夹下。在模板中不用管图片的位置,会自动根据文字以及图片大小调整。label仅仅用于图片在正文中的引用,采用Fig. \ ref { XX },其中XX是label名称,fig1,fig2,fig3,在引用中,诸如Fig. 和Tabel.的字眼需要手动添加,而 \ ref { XX }只是一个图片的编号,根据在.tex文件中出现的顺序自动编号,所以不用担心图片位置的变化而要改变编号,并且它会自动根据模板风格选择阿拉伯数字或是罗马数字。label会在texstudio的标签中显示,如图。

LaTeX外部模板(IEEEtrans)初次套用经历

%图片展示,在模板中不用管图片的位置,会自动根据文字以及图片大小调整
%figure是双栏的图片排版
\begin{figure}[!t]
	\centering %居中
	\includegraphics[scale=1]{2.jpg}%图片大小及加载的图片名称			
	\caption{show single picture.}%图片标题
	\label{fig1}%标注该图片,用于在文章内引用
\end{figure} 

%figure*是单栏的图片排版,用于大图片,双栏中放不下的
\begin{figure*}[!t]
	\centering
	\includegraphics[width=6in]{3.jpg}%
	\caption{Sample images of highway test dataset.}
	\label{fig2}
\end{figure*}

%多子图的情况
\begin{figure*}[!t]
	\centering
	\subfloat[first]{\includegraphics[width=4in]{2.jpg}
	}
	\hfil
	\subfloat[second]{\includegraphics[width=3in]{2.jpg}
	}
	\hfil\hfil
	\subfloat[third]{\includegraphics[width=5in]{2.jpg}
	}
	\hfil
	\subfloat[ fourth]{\includegraphics[width=2in]{2.jpg}
	}
	
	\caption{multiple features}
	\label{fig3}
\end{figure*}

表格的具体使用请参考其他详细资料。用LaTeX写简单表格比较容易,但是大型表格比较麻烦,因此可用参考LaTeX插入表格,用网页在线转换器(http://www.tablesgenerator.com/latex_tables)将可视化表格转换成LaTeX代码,将代码复制到相应位置,非常好用。

\begin{table}[!t]
	\renewcommand{\arraystretch}{1.3}
	\caption{show tabel.}%标注该表格,用于在文章内引用
	\label{table1}
	\centering
	\begin{tabular}{ccccc}
		\toprule	
		A & \multicolumn{3}{c}{B}  \\
		\cmidrule{2-4}
		& C & C2 & 3 \\	
		\midrule
		a1 & 0.4 & 0.9 & 0.8 \\
		a2 & 0.1 & 0.1& 0.9 \\
		a3 & 0.5 & 0.0& 0.5 \\
		a4 & 0.7 & 0.7& 0.7 \\
		
		\bottomrule
	\end{tabular}
\end{table}

公式具体使用请参考其他详细资料。

%行内公式,用$$包围
The $A_{1}=B+C(\dfrac{a}{a\log b})$President has told members of his team that starting a new conflict would amount to breaking his campaign promise to wind do.

%行间公式,公式文字内不好放的时候
\begin{equation}
A_{1}=B+C(\dfrac{a}{a\log b})
\end{equation}
o breaking his

%行间多行公式共用一个编号
\begin{equation}
\begin{aligned}	
A_{1}=B+C(\dfrac{a}{a\log b})\\
A_{1}=B+C(\dfrac{a}{a\log b})
\end{aligned}
\end{equation}

%一行太长写不下,一般在等号或加号出换行
o breaking his
\begin{multline}
A_{1}=B+C(\dfrac{a}{a\log b})+C(\dfrac{a}{a\log b})-C(\dfrac{a}{a\log b})+C(\dfrac{a}{a\log b})\\
=C(\dfrac{a}{a\log b})+C(\dfrac{a}{a\log b})+C(\dfrac{a}{a\log b})\\
=C(\dfrac{a}{a\log b})
\end{multline}

结合BibTeX自动导入并引用参考文献,首先在test_main.tex所处文件下存放一个BibTeX文件,命名为reference,即reference.bib,可从谷歌学术等地方导入参考文章的BibTXT,并复制到reference中。通过以下的方式自动加载,然后就可以直接引用参考文献了,用\cite{XX},XX是.bib文件中article后面的内容,如下图所示。

\bibliographystyle{IEEEtran}%这里选择的是IEEEtran,还可以选择不同的分风格

\bibliography{reference}%导入BibTeX.bib,然后就可以直接引用参考文献了,用\cite{XX},XX是.bib文件中article后面的内容,如上所示

%引用参考文献
members of\cite{olson1999nutrition} his team that starting a new conflict would amount to breaking his campaign promise\cite{townsend2001food} to winstarting a new conflict would amount to breaking his\cite{olson1999nutrition}.

LaTeX外部模板(IEEEtrans)初次套用经历LaTeX外部模板(IEEEtrans)初次套用经历

test_main.tex文件在编译过程中,会产生一些中间文件,有时候参考文献的更改会报错,把这些中间文件删除重新编译就又可以了。

LaTeX外部模板(IEEEtrans)初次套用经历