LaTeX是一种基于ΤΕΧ的排版系统,对于生成复杂表格和数学公式,这一点表现得尤为突出。因此它非常适用于生成高印刷质量的科技和数学类文档。
本文主要记录LaTex的语法文档。学习前,请先访问利用Atom构建LaTex文档开发环境,搭建好文档开发环境。
下面的文档教程都是以30分钟内快速学习LaTex上手毕业论文为目的,文档教程没有做详细解释。想了解完整的Latex教程,可以查看一份不太简短的LaTex介绍或一份其实很短的LaTex入门文档。至于LaTex代码所呈现的文档效果,请自己复制到Atom去构建Build查看PDF.
新建文档
新建一个demo.tex,输入如下内容:
\documentclass{article}
\begin{document}
hello !\\
hello again !
\end{document}
此例可以看出LaTex可以使用两个\换行,一行存在多个空格相邻,相邻的空格都当做一个空格处理。一篇LaTeX文档一般来说都是以article模板开始进行书写论文。
标题、作者、注释
\documentclass{article}
\author{My Name}
\title{The Title}
\begin{document}
\maketitle
hello, world % This is comment
\end{document}
文档中必须添加\maketitle,否则即使添加了\author和\title也不会出现标题和作者。%主要起到注释的作用,一行中出现%,LaTex将会自动忽略本行%后面的内容。(包括%)
章节和段落
\documentclass{article}
\title{Hello World}
\begin{document}
\maketitle
\section{Hello China} China is in East 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 Guangzhou}
\paragraph{Sun Yat-sen University} is the best university in Guangzhou.
\end{document}
添加目录
\documentclass{article}
\begin{document}
\tableofcontents
\section{Hello China} China is in East Asia.
\subsection{Hello Beijing} Beijing is the capital of China.
\subsubsection{Hello Dongcheng District}
\paragraph{Hello Tian'anmen Square}is in the center of Beijing
\subparagraph{Hello Chairman Mao} is in the center of Tian'anmen Square
\end{document}
换行
\documentclass{article}
\begin{document}
Beijing is
the capital
of China.
New York is
the capital
of America.
Amsterdam is \\ the capital \\
of Netherlands.
\end{document}
LaTex有两种换行方式,分别是使用两个\或空一行
数学公式
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}
The Newton's second law is F=ma.
The Newton's second law is $F=ma$.
The Newton's second law is
$$F=ma$$
The Newton's second law is
\[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}
这里并没有列出所有的LaTex数学公式。更多的数学公式请参考一份不太简短的LaTex介绍或一份其实很短的LaTex入门文档。
插入图片
图片和demo.tex文档同一个文件夹下。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=4.00in,height=3.00in]{figure1.jpg}
\end{document}
建立表格
\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|}
a & b \\
c & d\\
\end{tabular}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d\\
\hline
\end{tabular}
\begin{center}
\begin{tabular}{|c|c|}
\hline
a & b \\ \hline
c & d\\
\hline
\end{tabular}
\end{center}
\end{document}