LaTeX 快速参考表
基本 LaTeX 参考资料
[LaTeX](https://www.glukhov.org/zh-cn/post/2024/11/latex-install-overview/ “LaTeX - 安装与概述) 是一个功能强大的排版系统,被广泛用于 创建具有复杂格式的专业文档,如数学公式,特别是在学术领域。
这里有一份 [LaTeX 排版](https://www.glukhov.org/zh-cn/post/2024/12/latex-cheat-sheet/ “LaTeX 排版速查表) 的速查表。
基本 TeX/LaTeX 命令
基本 LaTeX 文档结构
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Your content here
\end{document}
文本格式
- 加粗:\textbf{text}
- 斜体:\textit{text}
- 下划线:\underline{text}
数学模式
行内数学公式:$$x^2 + y^2 = z^2$$ 显示数学公式:$$ E = mc^2 $$
希腊字母
- Alpha:$$\alpha$$
- Beta:$$\beta$$
- Gamma:$$\gamma$$
- Delta:$$\delta$$
运算符和符号
- 求和:$$\sum_{i=1}^n x_i$$
- 积分:$$\int_a^b f(x) dx$$
- 分数:$$\frac{numerator}{denominator}$$
- 平方根:$$\sqrt{x}$$
下标和上标
- 下标:$$x_i$$
- 上标:$$x^2$$
- 组合:$$x_i^2$$
矩阵
\begin{matrix}
a & b \\
c & d
\end{matrix}
方程
\begin{equation}
f(x) = ax^2 + bx + c
\end{equation}
列表
无序列表:
\begin{itemize}
\item 第一项
\item 第二项
\end{itemize}
有序列表:
\begin{enumerate}
\item 第一项
\item 第二项
\end{enumerate}
表格
请参见下面的独立部分。
\begin{tabular}{|c|c|}
\hline
标题1 & 标题2 \\
\hline
单元格1 & 单元格2 \\
\hline
\end{tabular}
章节
\section{主章节}
\subsection{子章节}
\subsubsection{子子章节}
请记住,根据您的具体需求,包含必要的包并使用适当的文档类。
添加图表
要在 LaTeX 速查表中添加图表,您有以下几种选择:
-
使用 graphicx 包插入图片:
- 在前导部分添加 \usepackage{graphicx}
- 使用 \includegraphics[选项]{文件名} 插入图片(请参见下方的详细信息。)
-
使用 venndiagram 包创建维恩图:
- 在前导部分添加 \usepackage{venndiagram}
- 使用 \begin{venndiagram3sets} 环境创建三集合图
-
使用 tikz 包绘制图形:
- 在前导部分添加 \usepackage{tikz}
- 使用 \begin{tikzpicture} 环境创建图表和图形
-
使用表格来组织信息:
- 使用 \begin{tabular} 环境创建简单表格
- 对于更复杂的表格,可以考虑使用 longtable 或 tabu 等包
-
使用子图来添加多个相关图表:
- 在前导部分添加 \usepackage{subcaption}
- 在 figure 环境中使用 \begin{subfigure} 环境
请记住调整图表的位置和大小以适应速查表格式。您可能需要尝试使用 [width=0.8\textwidth] 或 [scale=0.5] 等选项,以确保图表在速查表布局中合适。
添加图片
使用 LaTeX 中的 graphicx 包添加图片,请按照以下步骤操作:
- 在文档前导部分包含 graphicx 包:
\usepackage{graphicx}
- 将图片文件放在与 LaTeX 文件相同的目录中,或使用 \graphicspath 命令指定图片目录:
\graphicspath{{images/}}
- 在文档中使用 \includegraphics 命令插入图片:
\includegraphics[选项]{文件名}
- 为了更好地组织和格式化,将图片包装在 figure 环境中:
\begin{figure}[位置]
\centering
\includegraphics[选项]{文件名}
\caption{此处为标题}
\label{fig:标签}
\end{figure}
- 使用 width、height 或 scale 等选项调整图片大小:
\includegraphics[width=0.5\textwidth]{文件名}
- 使用 \ref 命令和分配的标签在文本中引用图片。
请记住编译文档以查看插入的图片。
在 LaTeX 文档中添加表格
在 LaTeX 文档中添加表格是一项常见任务,可以通过使用 tabular 环境来完成。
以下是使用多个示例在 LaTeX 中创建表格的方法:
基本表格结构
LaTeX 中表格的基本结构使用 tabular 环境:
\begin{tabular}{列说明}
内容
\end{tabular}
列说明定义了每列的对齐方式和边框:
- l:左对齐
- c:居中对齐
- r:右对齐
- |:列之间垂直线
简单表格示例
这是一个基本的 3x3 表格:
\begin{tabular}{lcr}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
带边框的表格
要添加边框,请使用垂直 (|) 和水平 (\hline) 线:
\begin{tabular}{|l|c|r|}
\hline
左 & 中心 & 右 \\
\hline
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
表格环境
为了更好的格式化和标题,请使用表格环境:
\begin{table}[h!]
\centering
\caption{示例表格}
\label{tab:sample}
\begin{tabular}{|c|c|c|}
\hline
列1 & 列2 & 列3 \\
\hline
A & B & C \\
D & E & F \\
\hline
\end{tabular}
\end{table}
多列和多行表格
对于更复杂的表格,可以使用 \multicolumn 和 \multirow 命令:
\usepackage{multirow}
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{2}{|c|}{合并的列} & 列3 \\
\hline
\multirow{2}{*}{合并的行} & B1 & C1 \\
& B2 & C2 \\
\hline
\end{tabular}
自定义列类型的表格
对于更高级的格式化,可以定义自定义列类型:
\usepackage{array}
\begin{tabular}{|l|>{\centering\arraybackslash}p{3cm}|r|}
\hline
左 & 居中的段落 & 右 \\
\hline
A & 此文本居中并在3厘米宽的列中换行 & 1 \\
\hline
\end{tabular}
请记住包含 array、multirow 或 booktabs 等包以实现高级表格功能。
添加目录
在 LaTeX 文档中添加目录是一个简单的过程。以下是操作方法:
- 基本目录
要创建基本目录,请使用 \tableofcontents 命令:
\documentclass{article}
\begin{document}
\tableofcontents
\section{简介}
\section{主要内容}
\section{结论}
\end{document}
这将根据文档的章节自动生成目录。
- 自定义目录
可以使用 \setcounter 命令自定义目录的深度:
\setcounter{tocdepth}{2}
\tableofcontents
这将显示章节和子章节在目录中。
- 更改标题
要更改默认的“目录”标题,请使用:
\renewcommand*\contentsname{教程}
\tableofcontents
这将把标题更改为“教程”。
- 添加无编号章节
要将无编号章节添加到目录中,请使用:
\addcontentsline{toc}{section}{无编号章节}
\section*{无编号章节}
这将把无编号章节包含在目录中。
- 添加图表和表格列表
您还可以添加图表和表格列表:
\tableofcontents
\listoffigures
\listoftables
请记住编译文档两次以确保目录正确生成。
示例
以下是一个完整示例,演示这些功能:
\documentclass{article}
\usepackage{blindtext}
\title{示例文档}
\author{约翰·多伊}
\date{}
\begin{document}
\maketitle
\renewcommand*\contentsname{文档目录}
\setcounter{tocdepth}{2}
\tableofcontents
\section{简介}
\blindtext
\section{主要内容}
\subsection{子章节1}
\blindtext
\subsection{子章节2}
\blindtext
\addcontentsline{toc}{section}{无编号章节}
\section*{无编号章节}
\blindtext
\section{结论}
\blindtext
\end{document}
此示例包括自定义目录标题、设置深度以包含子章节,并将无编号章节添加到目录中。