LaTeX 速查表
本页面汇总了 LaTeX 编程中最常用的语法和知识点,方便快速查阅。
文档结构
基本结构
\documentclass{article}
\begin{document}
文档内容
\end{document}
文档类
\documentclass{article} % 文章
\documentclass{report} % 报告
\documentclass{book} % 书籍
\documentclass{beamer} % 演示文稿
\documentclass{ctexart} % 中文文章
文档类选项
\documentclass[12pt, a4paper, twoside]{article}
导言区
常用宏包
\usepackage{amsmath} % 数学公式
\usepackage{graphicx} % 图片
\usepackage{hyperref} % 超链接
\usepackage{booktabs} % 专业表格
\usepackage{ctex} % 中文支持
\usepackage{xcolor} % 颜色
\usepackage{listings} % 代码
\usepackage{geometry} % 页面设置
页面设置
\usepackage{geometry}
\geometry{a4paper, margin=2.5cm}
标题信息
\title{标题}
\author{作者}
\date{\today}
\maketitle
章节命令
\part{部分}
\chapter{章}
\section{节}
\subsection{小节}
\subsubsection{子小节}
\paragraph{段落}
\subparagraph{子段落}
文本格式
字体样式
\textbf{粗体}
\textit{斜体}
\texttt{等宽}
\underline{下划线}
\textsc{小型大写}
字号
{\tiny 最小}
{\small 小}
{\normalsize 正常}
{\large 大}
{\Large 更大}
{\huge 巨大}
对齐
\begin{center}居中\end{center}
\begin{flushleft}左对齐\end{flushleft}
\begin{flushright}右对齐\end{flushright}
列表
\begin{itemize}
\item 无序列表
\end{itemize}
\begin{enumerate}
\item 有序列表
\end{enumerate}
\begin{description}
\item[术语] 描述
\end{description}
数学公式
行内公式
$E = mc^2$
\(E = mc^2\)
行间公式
\[E = mc^2\]
\begin{equation}
E = mc^2
\end{equation}
常用符号
$\alpha$ $\beta$ $\gamma$ $\delta$ $\epsilon$
$\sum$ $\prod$ $\int$ $\oint$
$\frac{a}{b}$ $\sqrt{x}$ $x^2$ $x_i$
$\leq$ $\geq$ $\neq$ $\approx$ $\equiv$
$\in$ $\subset$ $\cup$ $\cap$
$\rightarrow$ $\Rightarrow$ $\infty$
矩阵
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\begin{bmatrix} a & b \\ c & d \end{bmatrix}
\begin{vmatrix} a & b \\ c & d \end{vmatrix}
多行公式
\begin{align}
a &= b + c \\
&= d + e
\end{align}
表格
基本表格
\begin{tabular}{|c|c|c|}
\hline
列1 & 列2 & 列3 \\
\hline
数据1 & 数据2 & 数据3 \\
\hline
\end{tabular}
专业表格
\usepackage{booktabs}
\begin{tabular}{lcc}
\toprule
项目 & 数值1 & 数值2 \\
\midrule
项目1 & 100 & 200 \\
\bottomrule
\end{tabular}
浮动表格
\begin{table}[htbp]
\centering
\caption{表格标题}
\label{tab:example}
\begin{tabular}{|c|c|}
\hline
列1 & 列2 \\
\hline
\end{tabular}
\end{table}
图片
插入图片
\usepackage{graphicx}
\includegraphics[width=0.8\textwidth]{image.png}
浮动图片
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{image.png}
\caption{图片标题}
\label{fig:example}
\end{figure}
引用
交叉引用
\label{sec:intro}
\ref{sec:intro}
\pageref{sec:intro}
参考文献
\cite{lamport1994}
\bibliographystyle{plain}
\bibliography{references}
超链接
\usepackage{hyperref}
\href{https://example.com}{链接文本}
\url{https://example.com}
特殊字符
\# \$ \% \& \_ \{ \}
\\ \^ \~ \textbackslash
长度单位
cm 厘米
mm 毫米
in 英寸
pt 点
em M 宽度
ex x 高度
常用命令
空格
\quad % 1em
\qquad % 2em
\, % 小空格
\! % 负空格
~ % 不间断空格
换行分页
\\ % 换行
\newline % 换行
\newpage % 新页
\clearpage % 清空浮动体并新页
缩进
\noindent % 取消缩进
\indent % 强制缩进
脚注
\footnote{脚注内容}
目录
\tableofcontents % 目录
\listoffigures % 图目录
\listoftables % 表目录
代码
\begin{verbatim}
代码内容
\end{verbatim}
\usepackage{listings}
\begin{lstlisting}[language=Python]
代码内容
\end{lstlisting}
颜色
\usepackage{xcolor}
\textcolor{red}{红色文本}
\colorbox{yellow}{黄色背景}
自定义命令
\newcommand{\R}{\mathbb{R}}
\newcommand{\abs}[1]{\left| #1 \right|}
计数器
\setcounter{section}{0}
\addtocounter{section}{1}
\stepcounter{section}
编译流程
pdfLaTeX
pdflatex document.tex
XeLaTeX
xelatex document.tex
BibTeX
pdflatex document
bibtex document
pdflatex document
pdflatex document
中文文档
\documentclass{ctexart}
% 或
\documentclass{article}
\usepackage{ctex}
\begin{document}
中文内容
\end{document}
编译命令:
xelatex document.tex
常用环境
摘要
\begin{abstract}
摘要内容
\end{abstract}
引用
\begin{quote}
短引用
\end{quote}
\begin{quotation}
长引用
\end{quotation}
定理
\newtheorem{theorem}{定理}
\begin{theorem}
定理内容
\end{theorem}
\begin{proof}
证明内容
\end{proof}
常见问题
图片找不到
\graphicspath{{figures/}}
浮动体位置
\usepackage{float}
\begin{figure}[H]
中文显示问题
\usepackage{ctex}
% 使用 xelatex 编译