文章目录
Latex 的基本使用(快速入门)文档类型宏包标题正文章节目录图片表格列表定理环境页面页码
数学公式的输入方式(均在正文区输入)行内公式行间公式上下标分式括号加粗大括号多行公式矩阵和行列式
利用 LaTex 编写论文的简洁模板(仅供参考)1. 基础设置2. 定理环境3. 摘要与首页4. 目录5. 正文6. 参考文献7. 附录
完整代码
Latex 的基本使用(快速入门)
文档类型
Tex 有多种文档类型可选,如:
英文:article, report, book, beamer
中文:ctexart, ctexrep, ctexbook, ctexbeamer(这些类型自带了对中文的支持)
ctexart, ctexrep, ctexbook, ctexbeamer是ctex提供的四个中文文档类,
分别对应了LATEX的标准文档类article, report, book, beamer。 使用它们的时候将涉及到的所有源文件使用UTF-8编码保存。
其用途可从单词本身的意思得知,中文文档类型的用途与英文的相对应。
如:article主要用来排版学术论文、学术报告等,与之对应的ctexart则主要用来排版中文的学术论文、学术报告等。
不同的文件类型,编写的过程中也会有一定的差异,如果直接修改文件类型的话,甚至会报错。
在编辑框第一行,输入以下内容来设置文件类型:\documentclass{文档类型}
一般也可以在 \documentclass 处设置基本参数。(如默认字体大小为12pt,纸张大小为A4,单面打印。) 则,第一行内容需改为:\documentclass[12pt, a4paper, oneside]{文档类型}
文件的正文部分需要放入 document 环境中,在 document 环境外的部分不会出现在文件中。\documentclass{ctexart} %这里文档类型选为:ctexart
\begin{document}
这里是正文!!
\end{document}
宏包
为了完成一些功能(如定理环境),还需要在导言区,即 document 环境之前加载宏包。
加载宏包的代码是:\usepackage{}
与数学公式和定理环境相关的宏包有:amsmath、amsthm、amssymb,
用于插入图片的宏包为:graphicx 。
加载(amsmath, amsthm, amssymb, graphicx)宏包\usepackage{amsmath, amsthm, amssymb, graphicx}
在加载宏包时还可以设置基本参数。(如使用超链接宏包 hyperref,可以设置引用的颜色为黑色等) 代码如下:\usepackage[bookmarks=true, colorlinks, citecolor=blue, linkcolor=black]{hyperref}
标题
标题可以用 \title{} 设置;
作者可以用 \author{} 设置;
日期可以用 \data{} 设置;
这些都需要放在导言区(即 \begin{document} 之前)
为了在文档中显示标题信息,需要使用 \maketitle 。
示例:\documentclass{ctexart}
%导言区
\title{我的第一个 LaTex 文档}
\author{X.IO}
\date{today}
%正文区
\begin{document}
\maketitle
\end{document}
正文
正文可以直接在 document 环境中书写,
不需要加入空格来缩进,因为文档默认会进行首行缩进。
相邻的两行在编译时仍然会视为同一段。在 Latex 中,另起一段的方式是使用一行相隔,如下:
正文换段(另起一段的方式就是:使用一行相隔) \documentclass{ctexart}
%正文区
\begin{document}
这里是第一段。
这里是第二段。
\end{document}
这样编译出来就是两个段落。
在正文部分,多余的空格、回车等都会被自动忽略,这保证了全文排版不会突然多出一行或者多出一个空格。
正文换页(另起一页的方式就是:\newpage) \documentclass{ctexart}
%正文区
\begin{document}
这里是第一段。
\newpage
这里是第二段。
\end{document}
在正文中,可以设置局部的特殊字体(了解)
字体命令直立\textup{}意大利\textit{}倾斜\textsl{}小型大写\textsc{}加宽加粗\textbf{}
章节
章节可以用 \section{} 和 \subsection{} 命令来标记。
示例:\documentclass{ctexart}
%导言区
\title{我的第一个 LaTex 文档}
\author{X.IO}
\date{today}
%正文区
\begin{document}
\maketitle
\section{一级标题}
\subsection{二级标题}
这里是正文!!
\subsection{二级标题}
这里是正文!!
\end{document}
目录
有了章节之后,可以使用 \tableofcontents 命令在指定位置生成目录。
通常带有目录的文件需要编译两次,因为需要先在目录中生成 .toc 文件,再据此生成目录。
示例:\documentclass{ctexart}
%导言区
\title{我的第一个 LaTex 文档}
\author{X.IO}
\date{today}
%正文区
\begin{document}
\maketitle
\tableofcontents %目录在这里!!!
\section{一级标题}
\subsection{二级标题}
这里是正文!!
\subsection{二级标题}
这里是正文!!
\end{document}
图片
插入图片需要使用 graphicx 宏包.
插入一张图片 \documentclass{ctexart}
\usepackage{graphicx} % 插入图片所需引入的宏包;
%正文区
\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics[width=9.5cm,height=5cm]{IU.jpg}
\caption{IU}
\end{figure}
\end{document}
说明: 1. \usepackage{graphicx}为 插入图片所需引入的宏包;
2. [htbp]的作用是自动选择插入图片的最优位置
[h]当前位置。将图形放置在正文文本中给出该图形环境的地方。如果本页所剩的页面不够,这一参数将不起作用。
[t]顶部。将图形放置在页面的顶部。
[b]底部。将图形放置在页面的底部。
[p]浮动页。将图形放置在一只允许有浮动对象的页面上。
3. \centering 设置是让图片居中;
4. \includegraphicx[]{} 用于插入图片,可用[]添加图片尺寸;花括号{}中为图片相对路径,通常将图片放在与latex文档相同的路径下。
5. \caption{} 用于设置图片的标题
关于图片的路径说明:
1. 图片与源代码在同一路径,引用相对路径
2. 图片与源代码不再同一路径,引用绝对路径
并排插入多张图片并公用一个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}
说明: 1. 需要同时引入 \usepackage{graphicx} 和 \usepackage{subfigure} 宏包
2. \subfigure[第一张] ,括号[]中的内容为子图的标题
3. \quad,表示空格
4. \caption{IU图片集},为总标题
表格
可以直接使用 Create LaTeX tables online – TablesGenerator.com 来生成。
也可以使用示例方法:
Create LaTeX tables online – TablesGenerator.com
示例:\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}
列表
LaTex 中的列表环境包含:
无序列表 itemize、 有序列表 enumerate 和 描述 description .
示例 \documentclass{ctexart}
%正文区
\begin{document}
\begin{enumerate}
\item 这是第一点;
\item 这是第二点;
\item 这是第三点。
\end{enumerate}
\end{document}
可自定义 \item 的样式 \documentclass{ctexart}
%正文区
\begin{document}
\begin{enumerate}
\item[(1)] 这是第一点;
\item[(2)] 这是第二点;
\item[(3)] 这是第三点。
\end{enumerate}
\end{document}
定理环境
定理环境需要使用 amsthm 宏包,首先在导言区加入:\newtheorem{theorem}{定理}[section]
{theorem}:是环境的名称
{定理}:设置了该环境显示的名称“定理”
[section]:作用是让 theorem 环境在每个 section 中单独编号。
在正文中,用如下方式来加入一条定理: \documentclass{ctexart}
\usepackage{amsthm}
\newtheorem{theorem}{定理}[section]
%正文区
\begin{document}
\begin{theorem}[定理名称]
这里是定理的内容。
\end{theorem}
\end{document}
其中,
[定理名称]并不是必须的。
此外,还可以建立新的环境,如果要让新的环境和 theorem 环境一起计数的话,可以用如下方法:
\newtheorem{theorem}{定理}[section]
\newtheorem{definition}[theorem]{定义}
\newtheorem{lemma}[theorem]{引理}
\newtheorem{corollary}[theorem]{推论}
\newtheorem{example}[theorem]{例}
\newtheorem{proposition}[theorem]{命题}
定理的证明可以直接用 proof 环境。
页面
一般情况下,LaTex 默认的页边距很大,为了让每一页显示的内容更多一些,我们可以使用 geometry 宏包,并在导言区加入以下代码:
页边距设置 \usepackage{geometry}
\geometry{left=2.50cm,right=2.50cm,top=2.80cm,bottom=2.50cm}
当然,也可以在最开始选择文件类型时,设置页面的大小,如:a4paper、b5paper等。
行间距设置 \linespread{1.5}
页码
默认的页面编码方式是阿拉伯数字,也可以自己设置为小写罗马数字。
aiph:表示小写字母
Aiph:表示大写字母
roman:表示小写罗马数字
Roman:表示大写罗马数字
arabic:表示默认的阿拉伯数字
页码编码方式设置为小罗马数字 \documentclass{ctexart}
\pagenumbering{roman}
%正文区
\begin{document}
这里是第一页的第一段。
\newpage
这里是第二页的第一段。
\end{document}
设置页码从0开始: \documentclass{ctexart}
\setcounter{page}{0}
%正文区
\begin{document}
这里是第一页的第一段。
\newpage
这里是第二页的第一段。
\end{document}
数学公式的输入方式(均在正文区输入)
行内公式
行内公式通常使用 $..$ 来输入,这通常被称为公式环境。
示例:若 $a>0$, $b>0$, 则 $a+b>0.$
行间公式
行间公式需要用 $$..$$ 来输入。
示例:若 $a>0$, $b>0$, 则 $$ a+b>0. $$
上下标
上标可以用 ^ 输入,例如: a^n
下标可以用 _ 输入,例如:a_1
上下标只会读取第一个字符,如果上下标的内容较多的话,需要改成 ^{} 或 _{}
示例:$$ a^n $$
$$ a_1 $$
$$ a^{n+1} $$
$$ a_{n-1} $$
分式
分式可以用 \dfrac{}{} 来输入.
为了在行间、分子、分母或者指数上输入较小的公式,可以使用 \frac{}{}.
输入分式 $ \dfrac{a}{b} $
输入分式 $ a^\frac{1}{n} $
括号
括号可以直接用(..)输入,
但是需要注意的是,有时候括号内的内容高度较大,需要改用 \left(..\right)
直接使用 $ (2+a) $
需要改用 $ \left(1+\dfrac{1}{n}\right)^n $
加粗
对于加粗的公式,可以使用 bm 宏包,并用命令:\bm{} 实现加粗,
这样可以保留公式的斜体。
示例:$ \bm{\textsl{a+1}} $
大括号
可以使用 cases 环境,
可以用于分段函数或者方程组。
示例:$$
f(x)=\begin{cases}
x, & x>0, \\
-x, & x\leq 0.
\end{cases}
$$
多行公式
多行公式通常使用 aligned 环境。
示例:$$
\begin{aligned}
a & =b+c \\
& = d+e
\end{aligned}
$$
矩阵和行列式
矩阵可以用 bmatrix 环境和 pmatrix 环境,分别为方括号和圆括号。
示例:$$ %方括号
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
$$
$$ %圆括号
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
$$
利用 LaTex 编写论文的简洁模板(仅供参考)
论文模板具备以下要素:
1. 可以使用定理、定义、引理等环境,且它们标号一致。
2. 论文中具有摘要、关键词、目录、参考文献、附录等要素。
3. 引用和目录中有超链接。
4. 首页没有页码,目录使用罗马数字的页码,正文使用阿拉伯数字的页码。
1. 基础设置
选取的文档类型:ctexart
字号、纸张设置:12pt, a4paper
使用的宏包:amsmath, amsthm, amssymb, appendix, bm, graphicx, hyperref, mathrsfs
代码如下:
\documentclass[12pt,a4paper]{ctexart}
\usepackage{amsmath,amsthm,amssymb,appendix,bm,graphicx,hyperref,mathrsfs}
\title{\textbf{我的论文标题}}
\author{X.IO}
\date{}%日期(这里避免生成日期,具体看个人需求)
\linespread{1.5}
2. 定理环境
在使用 amsthm 宏包之后,就可以设置定理环境了。
代码如下:
\newtheorem{theorem}{定理}[section]
\newtheorem{definition}[theorem]{定义}
\newtheorem{lemma}[theorem]{引理}
\newtheorem{corollary}[theorem]{推论}
\newtheorem{example}[theorem]{例}
\newtheorem{proposition}[theorem]{命题}
其中[theorem]的作用是让所有的环境同 theorem 的编号。
3. 摘要与首页
在使用 abstractname 包之后,可以在导言区加入以下代码。
·首页没有页码
代码如下:
\maketitle
\setcounter{page}{0}
\maketitle
\thispagestyle{empty}
\begin{abstract}
这里是摘要。
\par\textbf{关键词:}这里是关键词;这里是关键词。
\end{abstract}
\newpage
4. 目录
1. 确保正文内容已经提前写好了。
2. 目录的页码使用罗马数字
代码如下:
\newpage
\pagenumbering{Roman}
\setcounter{page}{1}
\tableofcontents
5. 正文
正文使用的页码是阿拉伯数字。
代码如下:
\newpage
\setcounter{page}{1}
\pagenumbering{arabic}
\section{一级标题}
\subsection{二级标题}
这里是正文。
6. 参考文献
要加入参考文献可以使用 bibtex。
代码如下:
\newpage
\begin{thebibliography}{99}
\bibitem{a}作者. \emph{文献}[M]. 地点:出版社,年份。
\bibitem{b}作者. \emph{文献}[M]. 地点:出版社,年份。
\end{thebibliography}
7. 附录
在使用 appendix 宏包之后,就可以添加附录了。
代码如下:
\newpage
\begin{appendices}
\renewcommand{\thesection}{\Alph{section}}
\section{附录标题}
这里是附录。
\end{appendices}
完整代码
\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}
精彩文章
发表评论