[LaTex] The use and writing of LaTex (quick start, appendix: concise paper template code)

Basic use of Latex (quick start)

document type

Tex 有多种文档类型可选,如:
	英文:article, report, book, beamer
	中文:ctexart, ctexrep, ctexbook, ctexbeamer(这些类型自带了对中文的支持)
	
	ctexart, ctexrep, ctexbook, ctexbeamer是ctex提供的四个中文文档类,
	分别对应了LATEX的标准文档类article, report, book, beamer。 使用它们的时候将涉及到的所有源文件使用UTF-8编码保存。

	其用途可从单词本身的意思得知,中文文档类型的用途与英文的相对应。
	如:article主要用来排版学术论文、学术报告等,与之对应的ctexart则主要用来排版中文的学术论文、学术报告等。
	
	不同的文件类型,编写的过程中也会有一定的差异,如果直接修改文件类型的话,甚至会报错。
  1. In the first line of the edit box, enter the following content to set the file type:
    \documentclass{文档类型}
    
  2. Generally, basic parameters can also be set at \documentclass. (For example, the default font size is 12pt, the paper size is A4, and single-sided printing.)
    Then, the content of the first line needs to be changed to:
    \documentclass[12pt, a4paper, oneside]{文档类型}
    
  3. The body part of the document needs to be placed in the document environment, and the part outside the document environment will not appear in the document.
    \documentclass{ctexart}	%这里文档类型选为:ctexart
    \begin{document}
    这里是正文!!
    \end{document}
    
    insert image description here

macro package

为了完成一些功能(如定理环境),还需要在导言区,即 document 环境之前加载宏包。
加载宏包的代码是:\usepackage{}
与数学公式和定理环境相关的宏包有:amsmath、amsthm、amssymb,
用于插入图片的宏包为:graphicx 。
  1. Load (amsmath, amsthm, amssymb, graphicx) macro packages
    \usepackage{amsmath, amsthm, amssymb, graphicx}
    
  2. Basic parameters can also be set when loading the macro package. (If you use the hyperref macro package hyperref, you can set the color of the reference to black, etc.)
    The code is as follows:
    \usepackage[bookmarks=true, colorlinks, citecolor=blue, linkcolor=black]{hyperref}
    

title

标题可以用 \title{} 设置;
作者可以用 \author{} 设置;
日期可以用 \data{} 设置;
这些都需要放在导言区(即 \begin{document} 之前)
为了在文档中显示标题信息,需要使用 \maketitle 。
  1. Example:
    \documentclass{ctexart}
    
    %导言区
    
    \title{我的第一个 LaTex 文档}
    \author{X.IO}
    \date{today}
     
     %正文区
    \begin{document}
    \maketitle
    
    
    \end{document}
    

insert image description here

text

正文可以直接在 document 环境中书写,
不需要加入空格来缩进,因为文档默认会进行首行缩进。
相邻的两行在编译时仍然会视为同一段。在 Latex 中,另起一段的方式是使用一行相隔,如下:
  1. Change the paragraph of the text (the way to start another paragraph is: use a line to separate)

    \documentclass{ctexart}
    
    %正文区
    \begin{document}
    	这里是第一段。
    
    	这里是第二段。
    \end{document}
    

    insert image description here

    这样编译出来就是两个段落。
    在正文部分,多余的空格、回车等都会被自动忽略,这保证了全文排版不会突然多出一行或者多出一个空格。
    
  2. Text page change (the way to start another page is: \newpage)

    \documentclass{ctexart}
    
    %正文区
    \begin{document}
    	这里是第一段。
    	\newpage
    	这里是第二段。
    \end{document}
    

    insert image description here
    insert image description here

  3. In the text, you can set local special fonts (understand)

    the font Order
    upright \textup{}
    Italy \textit{}
    tilt \textsl{}
    small caps \textsc{}
    Widen and bold \textbf{}

chapter

章节可以用 \section{} 和 \subsection{} 命令来标记。
  1. Example:
    \documentclass{ctexart}
    
    %导言区
    
    \title{我的第一个 LaTex 文档}
    \author{X.IO}
    \date{today}
     
     %正文区
    \begin{document}
    \maketitle
    \section{一级标题}
    
    \subsection{二级标题}
    这里是正文!!
    
    \subsection{二级标题}
    这里是正文!!
    
    \end{document}
    
    insert image description here

Table of contents

有了章节之后,可以使用 \tableofcontents 命令在指定位置生成目录。
通常带有目录的文件需要编译两次,因为需要先在目录中生成 .toc 文件,再据此生成目录。
  1. Example:
    \documentclass{ctexart}
    
    %导言区
    
    \title{我的第一个 LaTex 文档}
    \author{X.IO}
    \date{today}
     
     %正文区
    \begin{document}
    \maketitle
    \tableofcontents	%目录在这里!!!
    \section{一级标题}
    
    \subsection{二级标题}
    这里是正文!!
    
    \subsection{二级标题}
    这里是正文!!
    
    \end{document}	
    
    insert image description here

picture

插入图片需要使用 graphicx 宏包.
  1. insert a picture

    \documentclass{ctexart}
    \usepackage{graphicx}	% 插入图片所需引入的宏包;
    
    %正文区
    \begin{document}
    	\begin{figure}[htbp]
    		\centering
    		\includegraphics[width=9.5cm,height=5cm]{IU.jpg}
    		\caption{IU}
    	\end{figure}
    \end{document}	
    

    insert image description here

    illustrate:

    1. \usepackage{graphicx}为 插入图片所需引入的宏包;
    2. [htbp]的作用是自动选择插入图片的最优位置
       [h]当前位置。将图形放置在正文文本中给出该图形环境的地方。如果本页所剩的页面不够,这一参数将不起作用。
       [t]顶部。将图形放置在页面的顶部。
       [b]底部。将图形放置在页面的底部。
       [p]浮动页。将图形放置在一只允许有浮动对象的页面上。
    3. \centering 设置是让图片居中;
    4. \includegraphicx[]{} 用于插入图片,可用[]添加图片尺寸;花括号{}中为图片相对路径,通常将图片放在与latex文档相同的路径下。
    5. \caption{} 用于设置图片的标题
    
    关于图片的路径说明:
    	1. 图片与源代码在同一路径,引用相对路径
    	2. 图片与源代码不再同一路径,引用绝对路径		
    
  2. Insert multiple pictures side by side and share a caption

    \documentclass[12pt,a4paper]{ctexart}
    \usepackage{graphicx}
    \usepackage{subfigure} 
    \begin{document}
    \begin{figure}[htbp]
    	\centering
    	\subfigure[第一张]{
    		\includegraphics[width=2.5cm,height=2.5cm]{img/IU.jpg} \label{1}
    	}
    	\quad
    	\subfigure[第二张]{
    		\includegraphics[width=2.5cm,height=2.5cm]{img/IU-3.png} \label{2}}
    	\quad
    	\subfigure[第三张]{
    		\includegraphics[width=2.5cm,height=2.5cm]{img/IU-8.jpg}\label{3}}
    	\quad
    	\subfigure[第四张]{
    		\includegraphics[width=2.5cm,height=2.5cm]{img/IU.jpg}\label{4}}
    	\caption{IU图片集}
    \end{figure}
    
    \end{document} 
    

    insert image description here
    illustrate:

    1. 需要同时引入 \usepackage{graphicx} 和 \usepackage{subfigure} 宏包
    2. \subfigure[第一张] ,括号[]中的内容为子图的标题
    3. \quad,表示空格
    4. \caption{IU图片集},为总标题
    

sheet

可以直接使用 Create LaTeX tables online – TablesGenerator.com 来生成。
也可以使用示例方法:

Create LaTeX tables online – TablesGenerator.com

  1. Example:
    \documentclass{ctexart}
    
    %正文区
    \begin{document}
    	\begin{table}[htbp]
    	\centering
    	\caption{表格标题}
    	\begin{tabular}{ccc}
    		1 & 2 & 3 \\
    		4 & 5 & 6 \\
    		7 & 8 & 9 \\
    	\end{tabular}
    	\end{table}
    \end{document}	
    
    insert image description here

the list

LaTex 中的列表环境包含:
	无序列表 itemize、	有序列表 enumerate 	和	描述 description .
  1. example

    \documentclass{ctexart}
    
    %正文区
    \begin{document}
    	\begin{enumerate}
    	\item 这是第一点;
    	\item 这是第二点;
    	\item 这是第三点。
    \end{enumerate}
    \end{document}	
    

    insert image description here

  2. Customize the style of \item

    \documentclass{ctexart}
    
    %正文区
    \begin{document}
    	\begin{enumerate}
    	\item[(1)] 这是第一点;
    	\item[(2)] 这是第二点;
    	\item[(3)] 这是第三点。
    \end{enumerate}
    \end{document}	
    

    insert image description here

Theorem environment

定理环境需要使用 amsthm 宏包,首先在导言区加入:\newtheorem{theorem}{定理}[section]
	{theorem}:是环境的名称
	{定理}:设置了该环境显示的名称“定理”
	[section]:作用是让 theorem 环境在每个 section 中单独编号。
  1. In the text, add a theorem as follows:

    \documentclass{ctexart}
    \usepackage{amsthm}
    \newtheorem{theorem}{定理}[section]
    
    %正文区
    \begin{document}
    	\begin{theorem}[定理名称]
    	这里是定理的内容。
    	\end{theorem}
    \end{document}	
    

    insert image description here

    其中,
    [定理名称]并不是必须的。
    此外,还可以建立新的环境,如果要让新的环境和 theorem 环境一起计数的话,可以用如下方法:
    
    \newtheorem{theorem}{定理}[section]
    \newtheorem{definition}[theorem]{定义}
    \newtheorem{lemma}[theorem]{引理}		
    \newtheorem{corollary}[theorem]{推论}
    \newtheorem{example}[theorem]{例}
    \newtheorem{proposition}[theorem]{命题}
    
    定理的证明可以直接用 proof 环境。
    

page

一般情况下,LaTex 默认的页边距很大,为了让每一页显示的内容更多一些,我们可以使用 geometry 宏包,并在导言区加入以下代码:
  1. margin settings

    \usepackage{geometry}
    \geometry{left=2.50cm,right=2.50cm,top=2.80cm,bottom=2.50cm}
    

    insert image description here

    insert image description here

    当然,也可以在最开始选择文件类型时,设置页面的大小,如:a4paper、b5paper等。
    
  2. line spacing settings

    \linespread{1.5}
    

    insert image description here

page number

默认的页面编码方式是阿拉伯数字,也可以自己设置为小写罗马数字。
aiph:表示小写字母
Aiph:表示大写字母
roman:表示小写罗马数字
Roman:表示大写罗马数字
arabic:表示默认的阿拉伯数字
  1. Page number encoding is set to Small Roman Numerals

    \documentclass{ctexart}
    \pagenumbering{roman}
    
    %正文区
    \begin{document}
    	这里是第一页的第一段。
    	\newpage
    	这里是第二页的第一段。
    \end{document}	
    

    insert image description here

    insert image description here

  2. Set the page number to start from 0:

    \documentclass{ctexart}
    \setcounter{page}{0}
    
    %正文区
    \begin{document}
    	这里是第一页的第一段。
    	\newpage
    	这里是第二页的第一段。
    \end{document}	
    

    insert image description here
    insert image description here

Input method of mathematical formula (all in the text area)

internal formula

行内公式通常使用 $..$ 来输入,这通常被称为公式环境。
  1. Example:
    若 $a>0$, $b>0$, 则 $a+b>0.$
    
    insert image description here

Interline formula

行间公式需要用 $$..$$ 来输入。
  1. Example:
    若 $a>0$, $b>0$, 则 $$ a+b>0. $$
    
    insert image description here

subscript

上标可以用 ^ 输入,例如: a^n
下标可以用 _ 输入,例如:a_1
上下标只会读取第一个字符,如果上下标的内容较多的话,需要改成  ^{} 或 _{}
  1. Example:
    $$ a^n $$
    $$ a_1 $$
    $$ a^{n+1} $$
    $$ a_{n-1} $$
    

insert image description here

Fraction

分式可以用 \dfrac{}{} 来输入.
为了在行间、分子、分母或者指数上输入较小的公式,可以使用 \frac{}{}.
  1. Enter fraction

    $ \dfrac{a}{b} $
    

    insert image description here

  2. Enter fraction

    $ a^\frac{1}{n} $
    

    insert image description here

brackets

括号可以直接用(..)输入,
但是需要注意的是,有时候括号内的内容高度较大,需要改用 \left(..\right)
  1. Use directly

    $ (2+a) $
    

    insert image description here

  2. need to use instead

    $ \left(1+\dfrac{1}{n}\right)^n $
    

    insert image description here

bold

对于加粗的公式,可以使用 bm 宏包,并用命令:\bm{} 实现加粗,
这样可以保留公式的斜体。
  1. Example:
    $ \bm{\textsl{a+1}} $
    
    insert image description here

big parantheses

可以使用 cases 环境,
可以用于分段函数或者方程组。
  1. Example:
    $$
    f(x)=\begin{cases}
    	x, & x>0, \\
    	-x, & x\leq 0.
    \end{cases}
    $$
    
    insert image description here

multiline formula

多行公式通常使用 aligned 环境。
  1. Example:
    $$ 
    \begin{aligned}
    a & =b+c \\
    & = d+e
    \end{aligned}
    $$
    
    insert image description here

Matrices and determinants

矩阵可以用 bmatrix 环境和 pmatrix 环境,分别为方括号和圆括号。
  1. Example:
    $$						%方括号
    \begin{bmatrix}
    	a & b \\
    	c & d
    \end{bmatrix}
    $$
    
    $$						%圆括号
    \begin{pmatrix}
    	a & b \\
    	c & d
    \end{pmatrix}
    $$	
    
    insert image description here

A concise template for writing papers in LaTex (for reference only)

论文模板具备以下要素:
	1. 可以使用定理、定义、引理等环境,且它们标号一致。
	2. 论文中具有摘要、关键词、目录、参考文献、附录等要素。
	3. 引用和目录中有超链接。
	4. 首页没有页码,目录使用罗马数字的页码,正文使用阿拉伯数字的页码。

1. Basic settings

选取的文档类型:ctexart
字号、纸张设置:12pt, a4paper
使用的宏包:amsmath, amsthm, amssymb, appendix, bm, graphicx, hyperref, mathrsfs

code show as below:

\documentclass[12pt,a4paper]{ctexart}
\usepackage{amsmath,amsthm,amssymb,appendix,bm,graphicx,hyperref,mathrsfs}

\title{\textbf{我的论文标题}}
\author{X.IO}
\date{}%日期(这里避免生成日期,具体看个人需求)
\linespread{1.5}	

2. Theorem environment

在使用 amsthm 宏包之后,就可以设置定理环境了。

code show as below:

\newtheorem{theorem}{定理}[section]
\newtheorem{definition}[theorem]{定义}
\newtheorem{lemma}[theorem]{引理}		
\newtheorem{corollary}[theorem]{推论}
\newtheorem{example}[theorem]{例}
\newtheorem{proposition}[theorem]{命题}

Among them, the role of [theorem] is to make all the environments the same number as theorem.

3. Summary and Home Page

在使用 abstractname 包之后,可以在导言区加入以下代码。
·首页没有页码

code show as below:

	\maketitle
	\setcounter{page}{0}
	\maketitle
	\thispagestyle{empty}
	
	\begin{abstract}
		这里是摘要。
		\par\textbf{关键词:}这里是关键词;这里是关键词。
	\end{abstract}
	\newpage

insert image description here

4. Contents

1. 确保正文内容已经提前写好了。
2. 目录的页码使用罗马数字

code show as below:

\newpage
\pagenumbering{Roman}
\setcounter{page}{1}
\tableofcontents

insert image description here

5. Text

正文使用的页码是阿拉伯数字。

code show as below:

\newpage
\setcounter{page}{1}
\pagenumbering{arabic}
\section{一级标题}
\subsection{二级标题}
这里是正文。

insert image description here

6. References

要加入参考文献可以使用 bibtex。

code show as below:

\newpage
\begin{thebibliography}{99}
	\bibitem{a}作者. \emph{文献}[M]. 地点:出版社,年份。
	\bibitem{b}作者. \emph{文献}[M]. 地点:出版社,年份。
\end{thebibliography}

insert image description here

7. Appendix

在使用 appendix 宏包之后,就可以添加附录了。

code show as below:

\newpage
\begin{appendices}
	\renewcommand{\thesection}{\Alph{section}}
	\section{附录标题}
		这里是附录。
\end{appendices}

insert image description here

full code

\documentclass[12pt,a4paper]{ctexart}
\usepackage{amsmath,amsthm,amssymb,appendix,bm,graphicx,hyperref,mathrsfs,abstract}

\title{\textbf{我的论文标题}}
\author{X.IO}
\date{}%日期(这里避免生成日期,具体看个人需求)
\linespread{1.5}

%%定理环境
\newtheorem{theorem}{定理}[section]
\newtheorem{definition}[theorem]{定义}
\newtheorem{lemma}[theorem]{引理}		
\newtheorem{corollary}[theorem]{推论}
\newtheorem{example}[theorem]{例}
\newtheorem{proposition}[theorem]{命题}

%%
\renewcommand{\abstractname}{\Large\textbf{摘要}}

\begin{document}
	\maketitle
	\setcounter{page}{0}
	\maketitle
	\thispagestyle{empty}
	
	\begin{abstract}
		这里是摘要。
		\par\textbf{关键词:}这里是关键词;这里是关键词。
	\end{abstract}
	\newpage
	\pagenumbering{Roman}
	\setcounter{page}{1}
	\tableofcontents
	
	\newpage
	\setcounter{page}{1}
	\pagenumbering{arabic}
	\section{一级标题}
	\subsection{二级标题}
	这里是正文。
	
	\newpage
	\begin{thebibliography}{99}
		\bibitem{a}作者. \emph{文献}[M]. 地点:出版社,年份。
		\bibitem{b}作者. \emph{文献}[M]. 地点:出版社,年份。
	\end{thebibliography}
	
	\newpage
	\begin{appendices}
		\renewcommand{\thesection}{\Alph{section}}
		\section{附录标题}
			这里是附录。
	\end{appendices}
	
\end{document} 

Guess you like

Origin blog.csdn.net/weixin_45954198/article/details/129723132