[洛谷日报#229]用 beamer 制作精美的演示文稿
StudyingFather
2019-09-12 20:07:57
## Part 1 啥是 beamer?
beamer 是 $\LaTeX$ 中的一个文档类,使用 beamer 可以让你非常方便地制作出美观的幻灯片用于演示。
## Part 2 准备工作
因为 beamer 是 $\LaTeX$ 中的一个文档类,在阅读下文之前,请先确保你完成了如下几个工作:
1. 掌握 $\LaTeX$ 的大部分基础语法。
2. 安装了 $\TeX$ Live 等 $\TeX$ 发行版。
本文将不再重复介绍 $\LaTeX$ 的基本语法。如果还不熟悉 $\LaTeX$ 的话,推荐阅读 [\[洛谷日报#165\]LaTeX 入门](https://www.luogu.org/blog/IowaBattleship/latex-ru-men) 以获取帮助。
## Part 3 Hello, World!
把下面的内容粘贴到你的 $\LaTeX$ 编辑器,编译之后查看一下效果吧!
```latex
\documentclass{beamer}
% 下面的内容会在标题页上展示
\title{Hello, World!}
\author{Studying Father}
\institute{SFOI Team}
\date{September 12th, 2019}
\begin{document}% 下面都是要显示的内容
\frame{\titlepage}% 显示标题页
\begin{frame}
\frametitle{Hello, World!}
Hello, World!
\end{frame}
\end{document}
```
(如果你无法正常编译的话,请使用 XeLaTeX 编译器进行编译)
如果不出意外的话,输出的 PDF 应该是长这样的:
![](https://cdn.luogu.com.cn/upload/image_hosting/ktnb9x8m.png)
![](https://cdn.luogu.com.cn/upload/image_hosting/kdt5age8.png)
接下来详细解释一下每条语句的含义:
- `\documentclass{beamer}` 指定了文档的种类为 beamer 类。
- `\frame{\titlepage}` 将显示标题页,你在导言区填写的标题 `\title{}`,作者 `\author{}`,机构 `\institute{}`,时间 `\date{}` 都将会显示在这一页上。
- `\begin{frame}` 到 `\end{frame}` 之间的部分是一个框架的内容。一个框架可以通过分页操作来输出多张幻灯片。
- `\frametitle{}` 是每一页的标题。
你也许会觉得这个幻灯片并不是那么美观,没关系,beamer 内置了很多主题和配色方案供你选择,你也可以写一个适合自己的模板!
关于主题自定义的问题,我们将在接下来的内容中讲述。
## Part 4 beamer 基本操作
beamer 兼容大多数 $\LaTeX$ 的命令和语法,因而对于 $\LaTeX$ 的命令和语法这里不再赘述,我们主要介绍一下 beamer 特有的操作。
### Part 4.1 目录页
对于较长的幻灯片,很多时候我们需要在开头部分显示目录。
添加目录页很简单,使用 `\tableofcontents` 命令即可。
试一下下面的代码吧!
```latex
\documentclass{beamer}
\title{Hello, World!}
\author{Studying Father}
\institute{SFOI Team}
\date{September 12th, 2019}
\begin{document}
\frame{\titlepage}
\begin{frame}
\frametitle{Content}
\tableofcontents % 这个命令将会显示目录
\end{frame}
\section{First Part} % 一级章节标题
\begin{frame}
\frametitle{Hello, World!}
Hello, World!
\end{frame}
\subsection{beamer} % 二级章节标题
\begin{frame}
\frametitle{beamer}
This is a beamer.
\end{frame}
\end{document}
```
注:在 $\LaTeX$ 中,需要编译两次才能正确显示目录。
显示的效果应该是这样的:
![](https://cdn.luogu.com.cn/upload/image_hosting/ce0fh1oo.png)
如果需要在每个部分的开头添加目录的话,请在引言区(`\begin{document}` 前面的部分)加入如下内容:
```latex
\AtBeginSection[]
{
\begin{frame}
\frametitle{Contents}
\tableofcontents[currentsection]
\end{frame}
}
```
这将会在每个 Section 的开头显示目录,并将会突出显示当前部分标题。
### Part 4.2 分页显示
使用 `\pause` 命令可以让一个框架内的内容分多张幻灯片显示。
```latex
\begin{frame}
\frametitle{Test}
QAQ\\
\pause
QwQ\\
\pause
QvQ
\end{frame}
```
最终将会有三张幻灯片:
![](https://cdn.luogu.com.cn/upload/image_hosting/yasupwqx.png)
![](https://cdn.luogu.com.cn/upload/image_hosting/zk9fartn.png)
![](https://cdn.luogu.com.cn/upload/image_hosting/bsdjv557.png)
### Part 4.3 文本框
可以用文本框来强调重要的内容,在 beamer 中,有三种文本框样式。
```latex
\begin{frame}
\frametitle{Title}
\begin{block}{QAQ}
QAQ
\end{block}
\begin{alertblock}{QwQ}
QwQ
\end{alertblock}
\begin{example} % 注意这里没有标题
QvQ
\end{example}
\end{frame}
```
注:对于不同的主题,文本框的显示效果可能有些差别。
## Part 5 自定义主题
在 beamer 中,有很多内置主题和配色方案可以选择。
你可以通过 `\usetheme{}` 更换主题,`\usecolortheme{}` 更换配色方案(这两条命令要放在导言区)。
[Beamer Theme Matrix](https://hartwork.org/beamer-theme-matrix/) 提供了所有主题和配色方案组合后的预览效果图(其中同一行代表相同的主题,同一列代表相同的配色方案)。
当然,你也可以写一个属于自己的 beamer 主题模板。感兴趣的可以自行查找相关资料。
## Reference
- [Beamer - Overleaf, Online LaTeX Editor](https://www.overleaf.com/learn/latex/Beamer)