第 1 个文档
\documentclass{article}
\begin{document}
hello, world
\end{document}
运行 xelatex test1.tex
,结果如下:
第 2 个文档: 标题、作者和注释
\documentclass{article}
\author{My Name}
\title{The Title}
\begin{document}
\maketitle
hello, world % This is comment
\end{document}
运行 xelatex test2.tex
,结果如下:
第 3 个文档: 章节和段落
\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}
运行 xelatex test3.tex
,结果如下:
第 4 个文档: 生成目录
\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}
\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}
第 5 个文档: 换行
空一行为另起一段,\\ 为段内强制换行:
\documentclass{article}
\begin{document}
Beijing is
the captical
of China.
Washington is
the captical
of America.
Amsterdam is \\ the captical \\
of Netherlands.
\end{document}
第 6 个文档: 数学公式
\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 differntial $\dot{F}$
Matrix (lcr here means left, center or right for each column)
\[
\left[
\begin{array}{lcr}
a1 & b22 & c333 \\
d444 & e55555 & 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}
第 7 个文档: 插入图像
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=4.0in, height3.0in]{figure1.jpg}
\end{document}
第 8 个文档: 插入简单的表格
\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|}
aaa & b \\
c & ddddd\\
\end{tabular}
\begin{tabular}{|l|r|}
\hline
aaaa & b \\
\hline
c & ddddd\\
\hline
\end{tabular}
\begin{center}
\begin{tabular}{|c|c|}
\hline
a & b \\ \hline
c & d\\
\hline
\end{tabular}
\end{center}
\end{document}
第 9 个文档: 中文
\documentclass{ctexart}
\begin{document}
你好,中国
\end{document}
宏包
\package{}
就是在调用宏包,对计算机实在外行的同学姑且可以理解为工具箱。
每一个宏包里都定义了一些专门的命令,通过这些命令可以实现对于一类对象(如数学公式等)的统一排版(如字号字形),或用来实现一些功能(如插入图片或制作复杂表格)。
通常在\documentclass
之后,在\begin{document}
之前,将文章所需要涉及的宏包都罗列上。
对于新人而言比较常用的宏包有编辑数学公式的宏包:
\usepackage{amsmath}
和\usepackage{amssymb}
编辑数学定理和证明过程的宏包:\usepackage{amsthm}
插入图片的宏包:\usepackage{graphicx}
复杂表格的宏包:\usepackage{multirow}
差不多了,对于新人来说,这五个宏包已经基本够用了。如果有其他的特殊需求,就通过 Google 去寻找吧。
补充说明一下,现在ctexart
模板里集成了中文支持,所以CJK
宏包并不是必需品。
模板
模板就是在
\documentclass{}
后面的大括号里的内容。
在这一份教程中,我们使用的是 LaTeX 默认自带的模板article
,以及中文模板ctexart
。模板就是实现我之前所介绍的 LaTeX 的经验总结的第二点的实现方式。
一篇文章,我们定义了section
,定义了paragraph
,就是没有定义字体字号,因为字体字号这一部分通常来说是在模板中实现的。
一个模板可以规定,section
这个层级都用什么字体什么字号怎么对齐,subsection
这个层级用什么字体什么字号怎么对齐,paragraph
又用什么字体什么字号怎么对齐。
当然模板里还可以包含一些自定义的口令,以及页眉页脚页边距一类的页面设置。
由于模板的使用,在我的使用经验里来看,绝对不可能算是基本入门级的内容,所以在正文里当然不会提及。
如果有人实在想学,如果 LaTeX 已经接触到这个程度上了,那么再去翻其他厚一些的教材,也不亏了。