LaTeX入门级教程

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

1.Tex Live2017的安装

    TEX是诞生于20世纪70年代末到80年代初的一款计算机排版软件,而且是命令行格式的(如下图),用来排版高质量的书籍,特别是包含有数学公式的书籍。TEX以追求高质量为目标,很早就实现了矢量描述的计算机字体、细致的分页断行算法和数学排版功能,因其数学排版能力得到了学术界的广泛使用,也启发了后来复杂的商业计算机排版软件。

    TEXLive是TEX的一个发行版,它是由TUG(TEX User Group,TEX用户组)发布的,可以在类UNIX/Linux、Mac OS X和Windows等不同的操作系统平台下安装使用,并且提供相当可靠的工作环境。

下载地址:

(速度很慢)官网:http://mirror.ctan.org/systems/texlive/Images/texlive2017.iso

百度云:https://pan.baidu.com/s/1c2enUhE

(推荐)清华的镜像站点:http://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texlive2017-20170524.iso

Tex Live的安装只需要执行iso里面的install-tl-advanced.bat文件,一路点下去即可安装。(安装时记得更改环境变量)

安装完以后可以在控制台输入 latex -v 来检查是否安装成功。

2.编辑器的安装

LaTeX的编辑器有许多种,根据个人喜好可以自行选择,这里我使用的是Texstudio

下载地址:http://texstudio.sourceforge.net/

按步骤安装即可,安装完以后打开Texstudio,点击Options->Configure texstudio->General->Language->zh_CN可以把界面更改为中文。同在设置里选择Build->Default Compiler更改为XeLateX,这样是为了能显示中文。

3.LaTeX的书写
3.1第一个文档

环境配置完以后就可以开始愉快的学习LaTeX了。新建我们的第一个文档,在里面输入

\documentclass[a4paper,oneside,12pt]{article}  
\begin{document}  
    hello,world 
\end{document}

点击那两个绿色的小三角来进行预览

结果如图


这样我们的第一份文档就完成了。其中的\begin{document}、\end{document}类似于html中的<body>,主体内容写在这里面。\documentclass用于定义文档的属性,在之后的[ ]中可以定义属性,例如\documentclass[12pt,oneside,a4paper]{book},{ }中表示的是文档的类型,一般有article,report,book,ctexart(可以显示中文)等。

3.2在LaTeX中显示中文

在编辑器里输入,注意:在编辑里将编码设置为UTF-8,否则可能出现乱码。

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{KaiTi}
    \author{你的名字}
    \title{标题}
    \begin{document}
        \maketitle
        你好,中文 %This is comment
    \end{document}

结果如图


可以看到,注释使用的是%,而要显示中文,需要在前面加上

\usepackage{fontspec}

\setmainfont[Mapping=text-text]{KaiTi}

这两句

3.3目录和标题的使用
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=text-text]{KaiTi}
\title{hello world}
\begin{document}
	\maketitle
	\tableofcontents
	\section{hello China}China is in Asia
	\subsection{hello beijing}beijing is the capital of China
	\subsubsection{hello dongcheng District}
	\paragraph{Tian'anmen Square}is in the center of Beijing
	\subparagraph{Chairman Mao}is in the center of Tian'anmen Square
	\subsection{Hello PoP and PiPiMi}
	\paragraph{Bobenemimimi}is the best in Jan.
\end{document}

结果如图


\tableofcontent用来生成目录,\section为标题,前面加一个sub便为下一级的标题,\paragraph也是如此

3.4 换行

LaTeX使用\\来进行强制换行,例如

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=text-text]{KaiTi}
\title{hello world}
\begin{document}
	aaa\\bbb\\ccc
\end{document}
3.5数学公式
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
	F=ma.\\
	$F=ma$\\
	Greek Letters $\eta$ and $\mu$
	Fraction $\frac{a}{b}$
	
	Power $a^b$
	
	Subscript $a_b$
	
	Derivate $\frac{\partial y}{\partial t} $
	
	Vector $\vec{n}$
	
	Bold $\mathbf{n}$
	
	To time differential $\dot{F}$
	
	Matrix (lcr here means left, center or right for each column)
	\[
	\left[
	\begin{array}{lcr}
	a1 & b22 & c333 \\
	d444 & e555555 & f6
	\end{array}
	\right]
	\]
	
	Equations(here \& is the symbol for aligning different rows)
	\begin{align}
	a+b&=c\\
	d&=e+f+g
	\end{align}
	
	\[
	\left\{
	\begin{aligned}
	&a+b=c\\
	&d=e+f+g
	\end{aligned}
	\right.
	\] 
\end{document}

上面是一些常用的数学符号,其他符号可以自行百度使用,$...$是行内数学模式,用于和文本一起使用

3.6插入图片
\documentclass{article}
\usepackage{graphicx}
\begin{document}
	\includegraphics[width=5.00in,height=4.00in]{asp.jpg}
\end{document}

结果如图

3.7简单表格
\documentclass{article}
\begin{document}
	\begin{tabular}{|c|c|}
		a & b \\
		c & d\\
	\end{tabular}
	
	
	\begin{center}
		\begin{tabular}{|c|c|}
			\hline
			a & b \\ \hline
			c & d\\
			\hline
		\end{tabular}
	\end{center}
\end{document} 
结果如图


3.8参考文献
建立一个新文档,把以下内容复制进入文档中,保存,保存文件名为references.bib,保存类型为UTF-8。这个文档专门用来存放参考文献的信息。具体参考https://blog.csdn.net/u013096666/article/details/72627001
@article{rivero2001resistance,
title={Resistance to cold and heat stress: accumulation of phenolic compounds in tomato and watermelon plants},
author={Rivero, Rosa M and Ruiz, Juan M and Garc{\i}a, Pablo C and L{\'o}pez-Lefebre, Luis R and S{\'a}nchez, Esteban and Romero, Luis},
journal={Plant Science},
volume={160},
number={2},
pages={315--321},
year={2001},
publisher={Elsevier}
}

@article{gostout1992clinical,
title={The clinical and endoscopic spectrum of the watermelon stomach},
author={Gostout, Christopher J and Viggiano, Thomas R and Ahlquist, David A and Wang, Kenneth K and Larson, Mark V and Balm, Rita},
journal={Journal of clinical gastroenterology},
volume={15},
number={3},
pages={256--263},
year={1992},
publisher={LWW}
}
建立一个新文档,把以下内容复制进入文档中,保存在同一个文件夹里
\documentclass{article}  
\usepackage[numbers]{natbib}  
\begin{document}  
    One reference about watermelon \cite{gostout1992clinical}%文档中使用引用         
    Another reference about watermelon \cite{rivero2001resistance}         
    \bibliographystyle{plain}   %参考文献的类型其它的类型包括
    %unsrt – 基本上跟 plain 类型一样, 除了参考文献的条目的编号是按照引用的顺序, 而不是按照作者的字母顺序.
    %alpha – 类似于 plain 类型, 当参考文献的条目的编号基于作者名字和出版年份的顺序.
    %abbrv – 缩写格式 .      
    \bibliography{references}%文件名   
\end{document} 

运行结果如图


以上为LaTeX的基本用法,一篇论文用到的基本语法大多概括到了,还有其他用法以及如何排版的更加美观,就需要自行摸索了。


参考:http://www.latexstudio.net/archives/10208

https://zhuanlan.zhihu.com/p/19779481?columnSlug=LaTeX

https://blog.csdn.net/u014803202/article/details/50410748


  • 20
    点赞
  • 103
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值