Contents
  1. One. LaTeX Document Structure
  2. 1.1 Basic Source File Structure
  3. 1.2 Handling Chinese
  4. 1.3 Font and Font Size Settings
  5. 1.4 Basic Document Structure
  6. Two. Special Characters in LaTeX
  7. Three. Figures and Tables in LaTeX
  8. 3.1 Figures
  9. 3.2 Tables
  10. Four. Floats in Latax
  11. Five. Mathematical Formulas in LaTeX
  12. Six. Bibliographies in LaTeX
  13. Seven. Custom Commands and Environments in LaTeX

One. LaTeX Document Structure

1.1 Basic Source File Structure

A LaTeX document is divided into a preamble and a body.

(1) Preamble

The preamble is mainly for global settings.

  • Use \documentclass{} to load a document class, such as the book, article, report, letter classes. Different classes have different formats; for example, book and letter have a cover, while the letter class has no title, and so on.
  • Use the \title{} command to define the document title
  • Use the \author{} command to define the document author
  • Use the \date{} command to define the document creation date
% 导言区
\documentclass{article} % book, report, letter

\title{My Latex Tutorial}
\author{Haofei Ma}
\date{\today} % \today指今天

(2) Body

The body is where you write the document content.

  • Use \begin{} and \end{} to enter an environment; {} holds the environment name. A latex file can have only one ducument environment
  • Use \maketitle to output the title
% 正文区  
\begin{document} % document为环境名称
	\maketitile
	
	% 内容(可以直接输入,空行代表段落)
	Hello World!

	Let $F(x)$ be defined by formula $$f(x)=3x^2-x+1$$.

\end{document}

1.2 Handling Chinese

Make sure the document encoding is UTF-8, and in the preamble use the \usepackage{ctex} command to load the ctex package.

When writing Chinese, you can use commands such as \heiti and \kaishu to set the font to Heiti, Kaishu, and so on.

%导言区  
\documentclass{article}

\title{\heiti Latex基础}%指定黑体字体  
\author{\kaishu 马浩飞}%指定楷书字体  
\date{\today}

\usepackage{ctex}%显示中文需要添加该指令

1.3 Font and Font Size Settings

Font and font size settings are all done in the body (because font settings apply only to a particular stretch of text).

(1) Font family settings

Use \textrm, \textsf, \textttt to set the font family.

Or use \rmfamily Roman Family to declare that the following text uses the Roman family.

%正文区
\begin{document}
%字体族设置(罗马字体、无衬线字体、打字机字体)

%\textrm等是字体命令,大括号里是作用到的文字
\textrm{Roman Family}
\textsf{Scan Serif Family}
\texttt{Typewriter Family}

%\rmfamily是字体声明,后面紧跟的文字是作用到的文字
{\rmfamily Roman Family}
{\sffamily Scan Serif Family}
{\ttfamily Typewriter Family}

\end{document}

Braces can limit the scope of a font declaration.

  • If you add braces, the font inside the braces is set to the specified font;
  • If there are no braces, all following paragraphs use the specified font.

When another font declaration is encountered, the current font declaration ends and the new one takes effect.

(2) Font series (weight, width)

%字体系列设置(粗细、宽度)
\textmd{Medium Series}%\设置字体宽度,大括号里是作用到的文字
\textbf{Boldface Series}% \textbf可以对字体加粗
{\mdseries Medium Series}%\设置字体宽度,大括号里是作用到的文字
{\bfseries Boldface Series}%字体声明

(3) Font shape (upright, italic, slanted, small caps)

%字体形状(直立、斜体、伪斜体、小型大写)
\textup{Upright Shape} \textit{Italic Shape} %字体命令
\textsl{Slanted Shape} \textsc{Small Caps Shape}

{\upshape Upright Shape} {\itshape Italic Shape }%字体声明
{\slshape Slanted Shape}
{\scshape Small Caps Shape}

(4) Chinese font settings

{\songti 宋体} \quad{heiti 黑体}\quad{\fangsong 仿宋}\quad {\kaishu 楷书}%\quad表示空格
中文字体的\textbf{粗体表现为黑体}与\textit{斜体表现为楷体}

(5) Font size

{\tiny  Hello }\\
{\scriptsize  Hello }\\
{\footnotesize  Hello }\\
{\small  Hello }\\
{\normalsize  Hello }\\
{\large  Hello }\\
{\Large  Hello }\\
{\LARGE  Hello }\\
{\huge  Hello }\\ 

1.4 Basic Document Structure

LaTeX uses commands such as \section{}, \subsection{}, \subsubsection{} to build the outline of an article.

%正文区
\begin{document}
	\maketitle %使得导言区的设置生效
	
	\section{引言} % 1 引言
	
	引言的内容第一段。
	
	使用空行来实现分段,这里是引言内容的第二段。
	
	\section{实验方法} % 2 实验方法
	\section{实验过程} % 3 实验过程
	\subsection{实验过程1} % 3.1 实验过程1
	\subsection{实验过程2} % 3.2 实验过程2
	\subsubsection{实验数据} % 3.2.1 实验数据
	\subsubsection{实验图表} % 3.2.2 实验图表
	\subsection{结果分析}  % 3.3 结果分析
	\section{结论} % 4 结论
	\section{致谢} % 5 致谢
	
\end{document}

Two. Special Characters in LaTeX

%正文区
\begin{document}
	\section{空白符号}
	% 空行分段,多个空行等同1个
	% 自动缩进,绝对不能使用空格代替
	% 英文中多个空格处理为1个空格,中文中空格将被忽略
	% 汉字与其它字符的间距会自动被处理
	% 禁止使用中文全角空格
	
	% 1em(当前字体中M的宽度)
	a\quad b
	
	% 2em
	a\qquad b
		
	% 1/6em
	a\,b a\thinspace b
		
	% 0.5em
	a\enspace b
			
	% 空格
	a\ b
				
	% 硬空格(不能分割的空格)
	a~b
					
	% 指定宽度的空格
	a\kern 1em b
	a\hspace{35pt}b
	
	% 占位宽度({}中的字符宽度)
	a\hphantom{xyz}b
				
	% 弹性长度(撑满整个空间)
	a\hfill b	
	
	\section{\ LaTex 控制符} % 相当于转义字符,`\`使用\textbackslash产生
	\# \$ \{  \} \~{} \_{} \^{} \textbackslash
	
	\section{排版符号}
	\S \P \dag \ddag \copyright \pounds
	
	\section{\ Tex 标志符号}
	\ TeX{} \ LaTeX{}  \ LaTeXe{}
	
	\section{引号}
	`'  %  `表示单引号的左边,'表示单引号的右边
	`` ''   %  ``表示双引号的左边,''表示双引号的右边
	``被引号包裹''
	
	\section{连字符}
	- -- ---

	\section{非英文字符}
	\oe \OE \AE \aa \AA \o \O \l \L \ss \SS !` ?`
	
	\section{重音符号}
	\`o \'o \^o \''o \~o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o} \b{o} \c{o} \d{o}

\end{document}

Three. Figures and Tables in LaTeX

3.1 Figures

In the preamble, use the \usepackage{grahpicx} command to load the graphicx package.

Syntax: \includegraphics[选项]{文件名}, where the options are used to set scale, rotation, and so on

Formats: EPS, PDF, PNG, JPEG, BMP

%导言区 
\documentclass{article}  
\title{My Latex Tutorial}
\author{Haofei Ma}
\date{\today}  
\usepackage{ctex}  
\usepackage{graphicx}  
\graphicspath{{figures/},{pics/}}%表示图片在当前目录下的figures目录或pics/目录

%正文区  
\begin{document}  
	% 插入图片
	\includegraphics{filename}  
	\includegraphics{filename2}  
	\includegraphics{filename3}%two是figures文件夹下的文件(图像)
	
	% 设置缩放比例
	\includegraphics[scale=0.3]{filename}  
	
	% 高度设置
	\includegraphics[height=0.1\textheight]{filename}  %文档高度0.1倍高度
	\includegraphics[height=2cm]{filename}
	
	% 宽度设置
	\includegraphics[width=0.1\textwidth]{filename}  % 文档宽度0.1倍宽度
	\includegraphics[width=2cm]{filename}  % 文档宽度0.1倍宽度
		
	% 旋转角度
	\includegraphics[angle=-45,width=2cm]{filename}  
\end{document}

3.2 Tables

Use the \begin{tabular} environment to create a table, and when creating the environment specify the number of columns and the alignment of each column

Syntax: \begin{tabular}[垂直对齐方式]{列格式说明}

  • l: left-align this column
  • c: center-align this column
  • r: right-align this column
  • p{宽度}: fixed column width; content wraps automatically when it exceeds the width
  • \\: line break
  • &: separate columns
  • |: whether to add a vertical rule between columns (|| for a double vertical rule)
  • \hline: add a horizontal rule between rows (\hline \hline for a double horizontal rule)
%正文区
\begin{document}
	\begin{tabular}{|l| c| c| c|  r|}%会有5列,指定每列的居中形式,|表示每列中间有竖线分开
		\hline%每行之间由横线分开
		姓名&语文&数学&外语&政治\\%\\表示换行
		\hline
		张三&87&120&25&36\\
		\hline
		张1&87&120&25&36\\
		\hline
		张2&87&120&25&36\\
		\hline
	\end{tabular}
	
\end{document}

Four. Floats in Latax

Five. Mathematical Formulas in LaTeX

Use the \equation{} command to produce a numbered display formula.

\begin{equation} %表示带编号的行间公式  
AB^2=BC^2+AC^2  
\end{equation}

Six. Bibliographies in LaTeX

Seven. Custom Commands and Environments in LaTeX