latex
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLaTeX Skill
LaTeX 使用技能
1. Overview
1. 概述
LaTeX is a markup language and typesetting system for producing high-quality documents. It excels at structured documents with complex formatting, mathematics, cross-references, and bibliographies.
When to use LaTeX:
- Academic papers, journal submissions
- Theses and dissertations
- Technical documentation
- CVs and résumés
- Presentations (Beamer)
- Books, reports, letters
Key concepts:
| Concept | Description |
|---|---|
| Preamble | Everything before |
| Document body | Content between |
| Commands | Start with |
| Environments | |
| Packages | Extensions loaded with |
LaTeX是一种用于生成高质量文档的标记语言和排版系统,尤其擅长处理包含复杂格式、数学公式、交叉引用和参考文献的结构化文档。
LaTeX适用场景:
- 学术论文、期刊投稿
- 硕士/博士学位论文
- 技术文档
- 个人简历(CVs/résumés)
- 演示文稿(Beamer)
- 书籍、报告、信函
核心概念:
| 概念 | 描述 |
|---|---|
| 导言区(Preamble) | 位于 |
| 文档主体(Document body) | 位于 |
| 命令(Commands) | 以 |
| 环境(Environments) | |
| 宏包(Packages) | 在导言区通过 |
2. Document Structure
2. 文档结构
Document Classes
文档类
latex
\documentclass[options]{class}| Class | Use case |
|---|---|
| Short documents, papers, assignments |
| Longer documents with chapters |
| Books (front/back matter, chapters) |
| Presentations/slides |
| Formal letters |
| Flexible — replaces article/report/book |
latex
\documentclass[options]{class}| 文档类 | 适用场景 |
|---|---|
| 短篇文档、论文、作业 |
| 包含章节的长篇文档 |
| 书籍(包含前言/后语、章节) |
| 演示文稿/幻灯片 |
| 正式信函 |
| 灵活通用的文档类,可替代article/report/book |
Common Class Options
常用文档类选项
latex
\documentclass[12pt,a4paper,twocolumn,draft]{article}| Option | Values |
|---|---|
| Font size | |
| Paper | |
| Columns | |
| Sides | |
| Draft | |
latex
\documentclass[12pt,a4paper,twocolumn,draft]{article}| 选项 | 可选值 |
|---|---|
| 字体大小 | |
| 纸张尺寸 | |
| 分栏方式 | |
| 单面/双面 | |
| 草稿模式 | |
Minimal Document
最小文档示例
latex
\documentclass[12pt,a4paper]{article}
% === PREAMBLE ===
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\title{My Document}
\author{Author Name}
\date{\today}
% === BODY ===
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
Content here.
\end{document}latex
\documentclass[12pt,a4paper]{article}
% === 导言区 ===
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\title{我的文档}
\author{作者姓名}
\date{\today}
% === 主体内容 ===
\begin{document}
\maketitle
\tableofcontents
\section{引言}
内容写在这里。
\end{document}3. Text Formatting
3. 文本格式设置
Style Commands
样式命令
| Command | Result |
|---|---|
| bold |
| italic |
| underlined |
| emphasis (italic, or upright if already italic) |
| |
| SMALL CAPS |
| sans-serif |
| 命令 | 效果 |
|---|---|
| 粗体 |
| 斜体 |
| 下划线 |
| 强调(默认斜体,若已为斜体则变为正体) |
| |
| 小型大写字母 |
| 无衬线字体 |
Font Sizes
字体大小
Smallest to largest:
\tiny \scriptsize \footnotesize \small \normalsize
\large \Large \LARGE \huge \HugeUse as: or as environment.
{\large This text is large.}从小到大依次为:
\tiny \scriptsize \footnotesize \small \normalsize
\large \Large \LARGE \huge \Huge使用方式: 或作为环境使用。
{\large 这段文字是大号字体。}Font Families
字体族
| Command | Declaration | Family |
|---|---|---|
| | Serif (Roman) |
| | Sans-serif |
| | Monospace |
| 命令 | 声明式命令 | 字体族 |
|---|---|---|
| | 衬线字体(罗马体) |
| | 无衬线字体 |
| | 等宽字体 |
Alignment
对齐方式
latex
\begin{center} Centered text. \end{center}
\begin{flushleft} Left-aligned. \end{flushleft}
\begin{flushright} Right-aligned. \end{flushright}Or inline: , ,
\centering\raggedright\raggedleftlatex
\begin{center} 居中对齐文本。 \end{center}
\begin{flushleft} 左对齐文本。 \end{flushleft}
\begin{flushright} 右对齐文本。 \end{flushright}或行内命令:、、
\centering\raggedright\raggedleftSpacing
间距设置
latex
\vspace{1cm} % vertical space
\hspace{2em} % horizontal space
\vfill % stretch vertical
\hfill % stretch horizontal
\\[0.5cm] % line break with extra space
\setlength{\parskip}{0.5em} % paragraph spacing
\setlength{\parindent}{0pt} % remove paragraph indent
\noindent % suppress indent for one paragraphLine spacing (requires package):
setspacelatex
\usepackage{setspace}
\onehalfspacing % or \doublespacing, \singlespacinglatex
\vspace{1cm} % 垂直间距
\hspace{2em} % 水平间距
\vfill % 可拉伸垂直间距
\hfill % 可拉伸水平间距
\\[0.5cm] % 换行并添加额外间距
\setlength{\parskip}{0.5em} % 段落间距
\setlength{\parindent}{0pt} % 取消段落首行缩进
\noindent % 取消当前段落的首行缩进行间距(需加载宏包):
setspacelatex
\usepackage{setspace}
\onehalfspacing % 或 \doublespacing(双倍行距)、\singlespacing(单倍行距)Special Characters
特殊字符
These characters must be escaped:
| Character | LaTeX | Character | LaTeX |
|---|---|---|---|
| | | |
| | | |
| | | |
| | | |
| | | |
以下字符需要转义后使用:
| 字符 | LaTeX写法 | 字符 | LaTeX写法 |
|---|---|---|---|
| | | |
| | | |
| | | |
| | | |
| | | |
4. Document Organization
4. 文档组织
Sectioning
章节划分
latex
\part{Part Title} % only in report/book
\chapter{Chapter Title} % only in report/book
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\paragraph{Paragraph}
\paragraphsub{Subparagraph}Starred versions () suppress numbering and TOC entry.
\section*{}latex
\part{篇标题} % 仅在report/book类中可用
\chapter{章标题} % 仅在report/book类中可用
\section{节}
\subsection{小节}
\subsubsection{子小节}
\paragraph{段落}
\paragraphsub{子段落}带星号的版本(如)会取消编号和目录条目。
\section*{}Table of Contents
目录
latex
\tableofcontents % requires two compilations
\listoffigures
\listoftableslatex
\tableofcontents % 需要编译两次才能生成正确目录
\listoffigures
\listoftablesLists
列表
latex
% Bulleted
\begin{itemize}
\item First item
\item Second item
\end{itemize}
% Numbered
\begin{enumerate}
\item First
\item Second
\end{enumerate}
% Labeled
\begin{description}
\item[Term] Definition here.
\end{description}Customize with package:
enumitemlatex
\usepackage{enumitem}
\begin{enumerate}[label=(\alph*), start=1]latex
% 无序列表
\begin{itemize}
\item 第一项
\item 第二项
\end{itemize}
% 有序列表
\begin{enumerate}
\item 第一项
\item 第二项
\end{enumerate}
% 描述列表
\begin{description}
\item[术语] 定义内容。
\end{description}使用宏包自定义列表:
enumitemlatex
\usepackage{enumitem}
\begin{enumerate}[label=(\alph*), start=1]Cross-References
交叉引用
latex
\section{Methods}\label{sec:methods}
See Section~\ref{sec:methods} on page~\pageref{sec:methods}.With , use for automatic "Section 2" text.
hyperref\autoref{sec:methods}Rule: Always place after (in floats) or after the sectioning command.
\label\captionlatex
\section{研究方法}\label{sec:methods}
请参见第~\ref{sec:methods}节,页码~\pageref{sec:methods}。加载宏包后,可使用自动生成类似“第2节”的文本。
hyperref\autoref{sec:methods}规则: 必须放在浮动体的之后,或章节命令之后。
\label\captionFootnotes
脚注
latex
This has a footnote.\footnote{Footnote text here.}latex
这段文字带有脚注。\footnote{脚注内容写在这里。}5. Mathematics
5. 数学公式
Inline vs Display
行内公式与行间公式
latex
Inline: $E = mc^2$ or \(E = mc^2\)
Display:
\[ E = mc^2 \]
% Numbered equation:
\begin{equation}\label{eq:einstein}
E = mc^2
\end{equation}latex
行内公式:$E = mc^2$ 或 \(E = mc^2\)
行间公式:
\[ E = mc^2 \]
% 带编号的公式:
\begin{equation}\label{eq:einstein}
E = mc^2
\end{equation}Essential Packages
必备宏包
latex
\usepackage{amsmath} % align, cases, matrices, etc.
\usepackage{amssymb} % extra symbols (ℝ, ℤ, etc.)
\usepackage{mathtools} % extends amsmath (dcases, coloneqq, etc.)latex
\usepackage{amsmath} % 增强的数学环境,如align、cases、矩阵等
\usepackage{amssymb} % 额外的数学符号(ℝ、ℤ等)
\usepackage{mathtools} % 扩展amsmath功能(如dcases、coloneqq等)Common Constructs
常用公式结构
latex
% Fractions
\frac{a}{b} \dfrac{a}{b} (display-size)
% Roots
\sqrt{x} \sqrt[3]{x}
% Sub/superscripts
x_{i} x^{2} x_{i}^{2} a_{i,j}
% Sums, products, integrals
\sum_{i=1}^{n} x_i \prod_{i=1}^{n} x_i
\int_{0}^{\infty} f(x)\,dx
\lim_{x \to \infty} f(x)
% Brackets (auto-sized)
\left( \frac{a}{b} \right)
\left[ ... \right]
\left\{ ... \right\}latex
% 分数
\frac{a}{b} \dfrac{a}{b} (行间公式大小的分数)
% 根式
\sqrt{x} \sqrt[3]{x}
% 下标/上标
x_{i} x^{2} x_{i}^{2} a_{i,j}
% 求和、乘积、积分
\sum_{i=1}^{n} x_i \prod_{i=1}^{n} x_i
\int_{0}^{\infty} f(x)\,dx
\lim_{x \to \infty} f(x)
% 自动调整大小的括号
\left( \frac{a}{b} \right)
\left[ ... \right]
\left\{ ... \right\}Matrices
矩阵
latex
\begin{pmatrix} a & b \\ c & d \end{pmatrix} % (a b; c d)
\begin{bmatrix} a & b \\ c & d \end{bmatrix} % [a b; c d]
\begin{vmatrix} a & b \\ c & d \end{vmatrix} % |a b; c d| (determinant)
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix} % {a b; c d}latex
\begin{pmatrix} a & b \\ c & d \end{pmatrix} % (a b; c d)
\begin{bmatrix} a & b \\ c & d \end{bmatrix} % [a b; c d]
\begin{vmatrix} a & b \\ c & d \end{vmatrix} % |a b; c d|(行列式)
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix} % {a b; c d}Aligned Equations
对齐公式
latex
\begin{align}
f(x) &= x^2 + 2x + 1 \label{eq:f} \\
g(x) &= x^3 - 1 \label{eq:g}
\end{align}
% No numbering:
\begin{align*}
a &= b + c \\
d &= e + f
\end{align*}latex
\begin{align}
f(x) &= x^2 + 2x + 1 \label{eq:f} \\
g(x) &= x^3 - 1 \label{eq:g}
\end{align}
% 无编号的对齐公式:
\begin{align*}
a &= b + c \\
d &= e + f
\end{align*}Cases
分段函数
latex
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases}latex
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases}Greek Letters
希腊字母
| Lower | Command | Upper | Command |
|---|---|---|---|
| α | | Α | |
| β | | Β | |
| γ | | Γ | |
| δ | | Δ | |
| ε | | Ε | |
| θ | | Θ | |
| λ | | Λ | |
| μ | | — | — |
| π | | Π | |
| σ | | Σ | |
| φ | | Φ | |
| ω | | Ω | |
| 小写 | 命令 | 大写 | 命令 |
|---|---|---|---|
| α | | Α | |
| β | | Β | |
| γ | | Γ | |
| δ | | Δ | |
| ε | | Ε | |
| θ | | Θ | |
| λ | | Λ | |
| μ | | — | — |
| π | | Π | |
| σ | | Σ | |
| φ | | Φ | |
| ω | | Ω | |
Common Math Symbols
常用数学符号
| Symbol | Command | Symbol | Command |
|---|---|---|---|
| ≤ | | ≥ | |
| ≠ | | ≈ | |
| ± | | × | |
| ÷ | | · | |
| ∈ | | ∉ | |
| ⊂ | | ⊆ | |
| ∪ | | ∩ | |
| ∞ | | ∂ | |
| ∇ | | ∀ | |
| ∃ | | → | |
| ⇒ | | ⇔ | |
| ℝ | | ℤ | |
| … | |
| 符号 | 命令 | 符号 | 命令 |
|---|---|---|---|
| ≤ | | ≥ | |
| ≠ | | ≈ | |
| ± | | × | |
| ÷ | | · | |
| ∈ | | ∉ | |
| ⊂ | | ⊆ | |
| ∪ | | ∩ | |
| ∞ | | ∂ | |
| ∇ | | ∀ | |
| ∃ | | → | |
| ⇒ | | ⇔ | |
| ℝ | | ℤ | |
| … | |
6. Tables
6. 表格
Basic Table
基础表格
latex
\begin{table}[htbp]
\centering
\caption{Results summary}\label{tab:results}
\begin{tabular}{lcrp{4cm}}
\toprule
Name & Count & Score & Description \\
\midrule
Alpha & 10 & 95.2 & First entry \\
Beta & 20 & 87.1 & Second entry \\
\bottomrule
\end{tabular}
\end{table}latex
\begin{table}[htbp]
\centering
\caption{结果汇总}\label{tab:results}
\begin{tabular}{lcrp{4cm}}
\toprule
名称 & 数量 & 得分 & 描述 \\
\midrule
Alpha & 10 & 95.2 & 第一条记录 \\
Beta & 20 & 87.1 & 第二条记录 \\
\bottomrule
\end{tabular}
\end{table}Column Specifiers
列格式说明
| Spec | Alignment |
|---|---|
| Left |
| Center |
| Right |
| Paragraph (top-aligned, fixed width) |
| Middle-aligned paragraph (requires |
| ` | ` |
| 格式符 | 对齐方式 |
|---|---|
| 左对齐 |
| 居中对齐 |
| 右对齐 |
| 段落式(顶部对齐,固定宽度) |
| 垂直居中的段落式(需加载 |
| ` | ` |
Key Packages
关键宏包
latex
\usepackage{booktabs} % \toprule, \midrule, \bottomrule (professional rules)
\usepackage{multirow} % \multirow{nrows}{width}{text}
\usepackage{longtable} % tables spanning multiple pages
\usepackage{tabularx} % auto-width X columnslatex
\usepackage{booktabs} % 提供\toprule、\midrule、\bottomrule(专业表格线)
\usepackage{multirow} % 提供\multirow{nrows}{width}{text}实现跨行单元格
\usepackage{longtable} % 支持跨多页的表格
\usepackage{tabularx} % 支持自动宽度的X列Multi-column/row
跨列/跨行单元格
latex
\multicolumn{3}{c}{Spanning header} \\
\multirow{2}{*}{Tall cell}latex
\multicolumn{3}{c}{跨三列的表头} \\
\multirow{2}{*}{跨行单元格}7. Figures and Images
7. 图表与图片
latex
\usepackage{graphicx}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{images/photo.png}
\caption{A descriptive caption.}\label{fig:photo}
\end{figure}latex
\usepackage{graphicx}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{images/photo.png}
\caption{描述性标题。}\label{fig:photo}
\end{figure}includegraphics Options
includegraphics 选项
| Option | Example |
|---|---|
| |
| |
| |
| |
| |
| 选项 | 示例 |
|---|---|
| |
| |
| |
| |
| |
Float Placement
浮动体位置参数
| Specifier | Meaning |
|---|---|
| Here (approximately) |
| Top of page |
| Bottom of page |
| Dedicated float page |
| Override internal limits |
| Exactly here (requires |
| 参数 | 含义 |
|---|---|
| 此处(尽可能靠近当前位置) |
| 页面顶部 |
| 页面底部 |
| 单独的浮动体页面 |
| 覆盖内部限制,强制放置 |
| 精确放置在当前位置(需加载 |
Subfigures
子图
latex
\usepackage{subcaption}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.48\textwidth}
\includegraphics[width=\textwidth]{img1.png}
\caption{First}\label{fig:sub1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\includegraphics[width=\textwidth]{img2.png}
\caption{Second}\label{fig:sub2}
\end{subfigure}
\caption{Both images}\label{fig:both}
\end{figure}latex
\usepackage{subcaption}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.48\textwidth}
\includegraphics[width=\textwidth]{img1.png}
\caption{第一张图}\label{fig:sub1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\includegraphics[width=\textwidth]{img2.png}
\caption{第二张图}\label{fig:sub2}
\end{subfigure}
\caption{两张图片合集}\label{fig:both}
\end{figure}8. Bibliographies and Citations
8. 参考文献与引用
BibTeX Workflow
BibTeX 工作流程
- Create :
references.bib
bibtex
@article{smith2023,
author = {Smith, John and Doe, Jane},
title = {An Important Paper},
journal = {Journal of Examples},
year = {2023},
volume = {42},
pages = {1--15},
doi = {10.1234/example}
}
@book{knuth1984,
author = {Knuth, Donald E.},
title = {The {\TeX}book},
publisher = {Addison-Wesley},
year = {1984}
}- In document:
latex
\usepackage{natbib} % or use biblatex
\bibliographystyle{plainnat}
As shown by \citet{smith2023}... % Smith and Doe (2023)
This is known \citep{smith2023}. % (Smith and Doe, 2023)
\bibliography{references}- Compile:
pdflatex → bibtex → pdflatex → pdflatex
- 创建文件:
references.bib
bibtex
@article{smith2023,
author = {Smith, John and Doe, Jane},
title = {An Important Paper},
journal = {Journal of Examples},
year = {2023},
volume = {42},
pages = {1--15},
doi = {10.1234/example}
}
@book{knuth1984,
author = {Knuth, Donald E.},
title = {The {\TeX}book},
publisher = {Addison-Wesley},
year = {1984}
}- 在文档中引用:
latex
\usepackage{natbib} % 或使用biblatex
\bibliographystyle{plainnat}
如\citet{smith2023}所示... % 显示为Smith and Doe (2023)
这一结论见\citep{smith2023}。 % 显示为(Smith and Doe, 2023)
\bibliography{references}- 编译顺序:
pdflatex → bibtex → pdflatex → pdflatex
BibLaTeX Workflow (Modern)
BibLaTeX 工作流程(现代方式)
latex
\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{references.bib}
\textcite{smith2023} % Smith and Doe (2023)
\parencite{smith2023} % (Smith and Doe, 2023)
\printbibliographyCompile:
pdflatex → biber → pdflatex → pdflatexlatex
\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{references.bib}
\textcite{smith2023} % 显示为Smith and Doe (2023)
\parencite{smith2023} % 显示为(Smith and Doe, 2023)
\printbibliography编译顺序:
pdflatex → biber → pdflatex → pdflatexnatbib vs biblatex
natbib vs biblatex
| Feature | natbib | biblatex |
|---|---|---|
| Backend | BibTeX | Biber (recommended) |
| Flexibility | Limited styles | Highly customizable |
| Unicode | Poor | Full support |
| Recommendation | Legacy projects | New projects |
| 特性 | natbib | biblatex |
|---|---|---|
| 后端工具 | BibTeX | Biber(推荐) |
| 灵活性 | 样式有限 | 高度可定制 |
| Unicode支持 | 差 | 完全支持 |
| 推荐场景 | 遗留项目 | 新项目 |
9. Code Listings
9. 代码列表
verbatim
verbatim 环境
latex
\begin{verbatim}
def hello():
print("Hello, world!")
\end{verbatim}
Inline: \verb|some_code()|latex
\begin{verbatim}
def hello():
print("Hello, world!")
\end{verbatim}
行内代码:\verb|some_code()|listings Package
listings 宏包
latex
\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{mystyle}{
basicstyle=\ttfamily\small,
keywordstyle=\color{blue},
commentstyle=\color{gray},
stringstyle=\color{red},
numbers=left,
numberstyle=\tiny,
frame=single,
breaklines=true
}
\begin{lstlisting}[language=Python, style=mystyle, caption={Example}]
def factorial(n):
"""Compute factorial."""
if n <= 1:
return 1
return n * factorial(n - 1)
\end{lstlisting}latex
\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{mystyle}{
basicstyle=\ttfamily\small,
keywordstyle=\color{blue},
commentstyle=\color{gray},
stringstyle=\color{red},
numbers=left,
numberstyle=\tiny,
frame=single,
breaklines=true
}
\begin{lstlisting}[language=Python, style=mystyle, caption={示例代码}]
def factorial(n):
"""计算阶乘。"""
if n <= 1:
return 1
return n * factorial(n - 1)
\end{lstlisting}minted Package (Prettier, Requires Pygments)
minted 宏包(更美观,需依赖Pygments)
latex
\usepackage{minted}
\begin{minted}[linenos, frame=lines, fontsize=\small]{python}
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
\end{minted}Compile with:
pdflatex -shell-escape document.texlatex
\usepackage{minted}
\begin{minted}[linenos, frame=lines, fontsize=\small]{python}
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
\end{minted}编译命令:
pdflatex -shell-escape document.tex10. Presentations (Beamer)
10. 演示文稿(Beamer)
latex
\documentclass{beamer}
\usetheme{Madrid} % or: Berlin, Warsaw, Metropolis, etc.
\usecolortheme{default} % or: beaver, crane, dolphin, etc.
\title{My Presentation}
\author{Author}
\date{\today}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Outline}
\tableofcontents
\end{frame}
\section{Introduction}
\begin{frame}{Introduction}
\begin{itemize}
\item<1-> First point (appears on slide 1+)
\item<2-> Second point (appears on slide 2+)
\item<3-> Third point
\end{itemize}
\end{frame}
\begin{frame}{With Columns}
\begin{columns}
\begin{column}{0.5\textwidth}
Left content
\end{column}
\begin{column}{0.5\textwidth}
Right content
\end{column}
\end{columns}
\end{frame}
\end{document}Popular themes: , , (modern, clean), ,
MadridBerlinMetropolisWarsawCambridgeUSlatex
\documentclass{beamer}
\usetheme{Madrid} % 可选主题:Berlin, Warsaw, Metropolis等
\usecolortheme{default} % 可选配色:beaver, crane, dolphin等
\title{我的演示文稿}
\author{作者}
\date{\today}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{目录}
\tableofcontents
\end{frame}
\section{引言}
\begin{frame}{引言}
\begin{itemize}
\item<1-> 第一点(从第1张幻灯片开始显示)
\item<2-> 第二点(从第2张幻灯片开始显示)
\item<3-> 第三点
\end{itemize}
\end{frame}
\begin{frame}{分栏布局}
\begin{columns}
\begin{column}{0.5\textwidth}
左侧内容
\end{column}
\begin{column}{0.5\textwidth}
右侧内容
\end{column}
\end{columns}
\end{frame}
\end{document}热门主题: 、、(现代简洁风格)、、
MadridBerlinMetropolisWarsawCambridgeUSOverlay Commands
叠加显示命令
| Command | Effect |
|---|---|
| Show content incrementally |
| Show on slide 2 only |
| Only on slide 1 (no space reserved) |
| Visible from slide 2 onward |
| Highlighted on slide 2 |
| 命令 | 效果 |
|---|---|
| 内容逐步显示 |
| 仅在第2张幻灯片显示 |
| 仅在第1张幻灯片显示(不保留空白) |
| 从第2张幻灯片开始显示 |
| 在第2张幻灯片高亮显示 |
11. Page Layout
11. 页面布局
Margins (geometry)
边距设置(geometry宏包)
latex
\usepackage[margin=2.5cm]{geometry}
% or:
\usepackage[top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}latex
\usepackage[margin=2.5cm]{geometry}
% 或自定义各边距:
\usepackage[top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}Headers and Footers (fancyhdr)
页眉页脚(fancyhdr宏包)
latex
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all
\fancyhead[L]{Left Header}
\fancyhead[R]{\rightmark} % current section
\fancyfoot[C]{\thepage} % page number center
\renewcommand{\headrulewidth}{0.4pt}latex
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % 清空所有默认设置
\fancyhead[L]{左侧页眉}
\fancyhead[R]{\rightmark} % 当前节标题
\fancyfoot[C]{\thepage} % 居中显示页码
\renewcommand{\headrulewidth}{0.4pt}Page Numbering
页码样式
latex
\pagenumbering{roman} % i, ii, iii (for front matter)
\pagenumbering{arabic} % 1, 2, 3 (for main content)
\thispagestyle{empty} % no number on this pagelatex
\pagenumbering{roman} % 罗马数字i, ii, iii(用于前言部分)
\pagenumbering{arabic} % 阿拉伯数字1, 2, 3(用于正文)
\thispagestyle{empty} % 当前页不显示页码Multi-Column
多栏布局
latex
\usepackage{multicol}
\begin{multicols}{2}
Content in two columns...
\end{multicols}latex
\usepackage{multicol}
\begin{multicols}{2}
双栏布局的内容...
\end{multicols}12. Common Packages Reference
12. 常用宏包参考
| Package | Purpose |
|---|---|
| Enhanced math environments |
| Extra math symbols (ℝ, ℤ, etc.) |
| Extensions to amsmath |
| Image inclusion |
| Clickable links, PDF metadata |
| Page margins and dimensions |
| Professional table rules |
| Multi-row table cells |
| Multi-page tables |
| Auto-width table columns |
| Color support |
| Code listings |
| Syntax-highlighted code (needs Pygments) |
| Programmatic graphics and diagrams |
| Data plots (built on TikZ) |
| Custom headers/footers |
| Line spacing |
| Customize list environments |
| Subfigures and subtables |
| Extra float control ( |
| Language/hyphenation support |
| Input encoding ( |
| Font encoding ( |
| Microtypographic enhancements |
| Smart cross-references ( |
| SI units and number formatting |
| Algorithm pseudocode |
| Citation management |
| Modern bibliography management |
| Context-sensitive quotation marks |
| Typeset URLs |
| Customize caption formatting |
| Appendix management |
Load order tip: Load last (or near-last). Exceptions: goes after .
hyperrefcleverefhyperref| 宏包 | 用途 |
|---|---|
| 增强数学环境 |
| 提供额外数学符号(ℝ、ℤ等) |
| 扩展amsmath功能 |
| 插入图片 |
| 生成可点击链接、PDF元数据 |
| 设置页面边距和尺寸 |
| 生成专业表格线 |
| 实现表格跨行单元格 |
| 生成跨多页的表格 |
| 自动调整表格列宽 |
| 支持颜色设置 |
| 插入代码列表 |
| 语法高亮代码块(需Pygments) |
| 编程方式绘制图形和图表 |
| 绘制数据图表(基于TikZ) |
| 自定义页眉页脚 |
| 设置行间距 |
| 自定义列表环境 |
| 生成子图和子表格 |
| 增强浮动体控制(如 |
| 支持多语言和断字 |
| 设置输入编码(如utf8) |
| 设置字体编码(如T1) |
| 微排版优化 |
| 智能交叉引用( |
| 排版SI单位和数字格式 |
| 排版算法伪代码 |
| 引用管理 |
| 现代参考文献管理 |
| 上下文敏感的引号 |
| 排版URL链接 |
| 自定义标题格式 |
| 附录管理 |
加载顺序提示: 宏包应最后加载(或接近最后)。例外:需在之后加载。
hyperrefcleverefhyperref13. Compilation
13. 编译
Engines
编译引擎
| Engine | Use when |
|---|---|
| Default. Most compatible. ASCII/Latin input. |
| System fonts (TTF/OTF), full Unicode |
| System fonts + Lua scripting, full Unicode |
| 引擎 | 适用场景 |
|---|---|
| 默认引擎,兼容性最好,支持ASCII/Latin编码 |
| 支持系统字体(TTF/OTF)和完整Unicode编码 |
| 支持系统字体+Lua脚本,完整Unicode编码 |
Compilation Sequence
编译顺序
bash
undefinedbash
% 基础文档编译
pdflatex document.tex
% 含参考文献的文档(BibTeX)
pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex
% 含参考文献的文档(Biber/BibLaTeX)
pdflatex document.tex
biber document
pdflatex document.tex
pdflatex document.tex
% 自动化编译(推荐)
latexmk -pdf document.tex % 使用pdflatex编译
latexmk -xelatex document.tex % 使用xelatex编译
latexmk -lualatex document.tex % 使用lualatex编译
latexmk -pdf -pvc document.tex % 实时预览,自动重新编译Basic document
常见错误及解决方法
pdflatex document.tex
| 错误信息 | 原因 | 解决方法 |
|---|---|---|
| 命令拼写错误或缺少对应宏包 | 检查命令拼写;添加 |
| 数学符号未放在数学环境中 | 将符号包裹在 |
| 导言区存在错误 | 检查导言区的语法错误 |
| 文件路径错误或文件缺失 | 检查文件名和路径;确认文件扩展名正确 |
| 行宽超过页面宽度 | 重新措辞;添加 |
| 参考文献条目缺失或未运行bibtex | 运行bibtex/biber;检查.bib文件中的引用键 |
| 待处理的浮动体过多 | 添加 |
| 图片缩放参数错误 | 检查 |
| 两个宏包冲突 | 只加载其中一个;查阅宏包文档确认兼容性 |
With bibliography (BibTeX)
阅读日志文件
pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex
- 查看文件获取完整错误上下文
.log - 错误以开头的行显示
! - 警告以或
LaTeX Warning:开头Package xyz Warning: - 出现提示时,需再次编译文档
Rerun to get cross-references right
With bibliography (Biber/BibLaTeX)
14. 技巧与最佳实践
pdflatex document.tex
biber document
pdflatex document.tex
pdflatex document.tex
- 多文件项目: 使用(直接插入内容)或
\input{chapters/intro}(自动添加\include{chapters/intro},支持\clearpage命令)\includeonly - 自定义导言区: 将宏包加载等设置移至或
preamble.sty,然后通过preamble.tex导入\input{preamble} - 标签位置: —— 标签必须放在标题之后,绝不能颠倒顺序
\caption{...}\label{fig:x} - 非断空格: 使用、
Figure~\ref{fig:x}—— 避免在标签编号前换行Section~\ref{sec:y} - 草稿模式: —— 加快编译速度,显示超宽行标记
\documentclass[draft]{article} - 浮动体中用而非
\centering—— 避免额外垂直间距center - 避免用换行来分隔段落 —— 改用空白行
\\ - 使用宏包 —— 专业表格避免使用
booktabs和竖线\hline - 加载宏包 —— 零成本提升排版质量
microtype - 使用宏包 ——
cleveref自动生成“图1”这类文本\cref{fig:x} - 版本控制: LaTeX是纯文本文件,推荐使用Git进行版本管理
- 每行一个句子 —— 便于在版本控制系统中查看差异
Automated (recommended)
15. 快速参考
—
最常用命令
latexmk -pdf document.tex # pdflatex
latexmk -xelatex document.tex # xelatex
latexmk -lualatex document.tex # lualatex
latexmk -pdf -pvc document.tex # continuous preview
undefined| 任务 | 命令 |
|---|---|
| 粗体 | |
| 斜体 | |
| 等宽字体 | |
| 创建节 | |
| 交叉引用 | |
| 引用文献 | |
| 添加脚注 | |
| 插入图片 | |
| 插入URL | |
| 列表项 | |
| 新页面 | |
| 注释 | |
| 行内数学公式 | |
| 行间数学公式 | |
| 分数 | |
Common Errors and Fixes
数学运算符
| Error | Cause | Fix |
|---|---|---|
| Typo or missing package | Check spelling; add |
| Math symbol outside math mode | Wrap in |
| Error in preamble | Check preamble for typos |
| Wrong path or missing file | Check filename/path, check extension |
| Line too wide | Rephrase, add |
| Missing bib entry or no bibtex run | Run bibtex/biber, check .bib keys |
| Too many figures queued | Add |
| Image scaling issue | Check |
| Two packages conflict | Load one, check docs for compatibility |
| 命令 | 符号 | 命令 | 符号 |
|---|---|---|---|
| sin | | cos |
| tan | | log |
| ln | | exp |
| min | | max |
| lim | | Σ |
| Π | | ∫ |
Reading Log Files
箭头符号
- Look at the file for full error context
.log - Errors show as lines
! - Warnings show as or
LaTeX Warning:Package xyz Warning: - → compile again
Rerun to get cross-references right
| 命令 | 符号 |
|---|---|
| → |
| ← |
| ↔ |
| ⇒ |
| ⇐ |
| ⇔ |
| ↦ |
| ↑ |
| ↓ |
14. Tips and Best Practices
参考资料
- Multi-file projects: Use (inserts inline) or
\input{chapters/intro}(adds\include{chapters/intro}, enables\clearpage)\includeonly - Custom preamble: Move package loading to or
preamble.sty, thenpreamble.tex\input{preamble} - Label after caption: — never the reverse
\caption{...}\label{fig:x} - Non-breaking spaces: ,
Figure~\ref{fig:x}— prevents linebreak before numberSection~\ref{sec:y} - Draft mode: — speeds compilation, shows overfull boxes
\documentclass[draft]{article} - Use not
\centeringinside floats (avoids extra vertical spacing)center - Avoid for paragraph breaks — use blank lines instead
\\ - Use — never
booktabsand vertical lines for professional tables\hline - Use — improves typography with zero effort
microtype - Use —
cleverefauto-generates "Figure 1" text\cref{fig:x} - Version control: LaTeX is plain text — use Git
- One sentence per line — makes diffs cleaner in version control
15. Quick Reference
—
Most Common Commands
—
| Task | Command |
|---|---|
| Bold | |
| Italic | |
| Monospace | |
| Section | |
| Reference | |
| Citation | |
| Footnote | |
| Image | |
| URL | |
| List item | |
| New page | |
| Comment | |
| Math inline | |
| Math display | |
| Fraction | |
—
Math Operators
—
| Command | Symbol | Command | Symbol |
|---|---|---|---|
| sin | | cos |
| tan | | log |
| ln | | exp |
| min | | max |
| lim | | Σ |
| Π | | ∫ |
—
Arrows
—
| Command | Symbol |
|---|---|
| → |
| ← |
| ↔ |
| ⇒ |
| ⇐ |
| ⇔ |
| ↦ |
| ↑ |
| ↓ |
—
References
—