Beamer-LaTeX学习(教程批注版)【6】
1 27个内建主题展示
原教程接下来展示了Beamer中27个内建的主题。个人觉得这一段只需要简单带过就可以。占的版面很大,实际上只是同一段代码,修改一下主题的名称看看差别罢了。
这27个内建主题的名称还是要大概看一下:
名称 | 名称 | 名称 |
---|---|---|
default | Darmstadt | Malmoe |
AnnArbor | Dresden | Marburg |
Antibes | Frankfurt | Montpellier |
Bergen | Goettingen | PaloAlto |
Berkeley | Hannover | Pittsburgh |
Berlin | Ilmenau | Rochester |
Boadilla | JuanLesPins | Singapore |
CambridgeUS | Luebeck | Szeged |
Copenhagen | Madrid | Warsaw |
%Inbuilt themes in beamer
\documentclass{beamer}% Theme choice: 主题只需要在这里修改就可以看到不同的效果
\usetheme{CambridgeUS}% Title page details:
\title{Beamer Inbuilt Themes (CambridgeUS)}
\author{latex-beamer.com}
\date{\today}
\logo{\large \LaTeX{}}\begin{document}% Title page frame
\begin{frame}\titlepage
\end{frame}% Remove logo from the next slides
\logo{}% Outline frame
\begin{frame}{Outline}\tableofcontents
\end{frame}% Lists frame
\section{Lists in Beamer}
\begin{frame}{Lists in Beamer}This is an unordered list:
\begin{itemize}\item Item 1\item Item 2\item Item 3
\end{itemize}and this is an ordered list:
\begin{enumerate}\item Item 1\item Item 2\item Item 3
\end{enumerate}\end{frame}% Blocks frame
\section{Blocks in Beamer}
\begin{frame}{Blocks in Beamer}\begin{block}{Standard Block}This is a standard block.\end{block}\begin{alertblock}{Alert Message}This block presents alert message.\end{alertblock}\begin{exampleblock}{An example of typesetting tool}Example: MS Word, \LaTeX{}\end{exampleblock}
\end{frame} \end{document}
这里小白就不进行贴图了。就是一个很简单的效果演示。
当然此处衍生出一个问题:除了这些内建的主题之外,如果需要新建自己的主题,应该怎么办?
关于这个问题小白先挖个小坑,这一块后续等小白自己研究透了再来与大家分享。
2 字体的修改
本课的重点在于对beamer中的字体进行修改。在英文里其实主要就是粗体、意大利斜体,以及下划线,包括一些装饰性字体、数学公式中的字体,然后还有字号和颜色等。
2.1 加粗、意大利斜体及下划线
文件中常用文本的字体来强调特殊段落,比如重要的概念或定义,字体的变化令整份文件具备更优的可读性。
在beamer中,我们能够通过命令
\textbf
,\textit
,\underline
分别打出粗体、意大利斜体、下划线字体。
这几个命令也可以组合使用,产生叠加的效果。但我们首先需要注意叠加的效果是否能够实现。例如我们可以将粗体和意大利斜体组合起来,但默认字体不支持,而编码为T1或者下载lmodern包使用拉丁现代字体族时则可以显示。
在接下来这个示例中,我们展示了如何使用这些组合:
% Bold, Italics and underline text in Beamer
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% change the font encoding
\usepackage[T1]{fontenc}% or either load the latin modern font
% \usepackage{lmodern}\begin{document}\begin{frame}{Bold, Italics and Underlining}This is how \textbf{bold}, \textit{italized} and
\underline{underlined} text looks.
You can also combine them, like \textbf{\textit{bold
italized}}, \underline{\textbf{bold underlined}} and
\textit{\underline{italized underlined}}.
Finally, you can put
\textbf{\textit{\underline{everything together}}}.\end{frame}\end{document}
注意到使用了T1包。
效果如下图所示:
注意,本例与小白前面所用的设置不能混用,因为小白前面几篇文章中使用了自定义的中文字体,会与当前课程的字体设置发生冲突。
2.2 斜体和强调文本
2.2.1 斜体
除了前面提到的三种基础字体之外,beamer还提供其他一些不常见的字体形式。textsl
命令创建斜体,虽说和意大利斜体有些类似,但是它保持了常规字体族的字母样式。
\textsc
命令创建的是小字体大写文本,这通常用来替代小写字母,但比大写字母的字号更小。
% Slanted and Small Cap text
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% select the KP Sans-Serif font
\usepackage[sfmath]{kpfonts}\begin{document}\begin{frame}{Slanted and small caps text}This is \textsc{small caps text} and this is
\textsl{slanted text}.\\~\\ You can combine them, to produce \textsl{\textsc{small
caps slanted text}} but also \textsc{\textbf{bold small caps}} or \textsl{\underline{underlined slanted text}}.\end{frame}\end{document}
和前面一个示例的情况类似,字体的组合需要建立在是否支持的基础之上。这里使用了KP Sans-Serif字体来支持字体组合。
2.2.2 强调文本
最后,LaTeX\LaTeX{}LATEX提供一个“趁手”的命令,叫作 \emph
,它可以比较智能地强调文本。意思是,当在正文中,该命令会将待强调的文本变成意大利斜体,而在意大利斜体中,将待强调的文本变成正文字体。
% Emphasized text
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}\begin{document}\begin{frame}{Emphasized text}\emph{This} is emphasized and \textit{\emph{this} is
also emphasized, although in a different way.}\end{frame}\end{document}
小白按:这里似乎出现了点问题,小白这边测试出来的结果和教程网站上的结果是一致的,但后一个this
并没有被成功强调。这里小白还要再研究一下。
2.2.3 数学公式加粗
在数学公式中,我们加粗的方式不同,不再使用
\textbf
,可以使用\bm
即bold math.
代码如下:
% Emphasized text
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% Required package
\usepackage{bm}\begin{document}\begin{frame}{Bold math example}Let $\bm{u}$, $\bm{v}$ be vectors and $\bm{A}$ be a
matrix such that $\bm{Au}=\bm{v}$.
This is a bold integral:
\[
\bm{\int_{-\infty}^{\infty} e^{-x^2}\,dx=\sqrt{\pi} }
\]\end{frame}\end{document}
效果如下:
2.2.4 Beamer中的文本修饰
我们已经看到如何通过LaTeX\LaTeX{}LATEX中的\underline
命令来生成下划线。接下来我们想更进一步学习如何对文本做各种各样的修饰。为了实现这一点,我们使用ulem包。
这个包改变了
\emph
命令工作的方式,不再在强调时采用意大利斜体,而是下划线。它同时引入了命令\uline
来给文本添加下划线。另外,新的下划线也同\underline
不同,后者不会在线的末尾中段,但前者会。
但ulem包的作用不止于此,它还提供了另外的6种修饰方式。
Description | 中文注释 | Command |
---|---|---|
Underline text solid line | 实线下划线 | \uline{} |
Double-Underlined text | 双实线下划线 | \uuline{} |
Dashed Underline text | 虚线下划线 | \dashuline{} |
Dotted Underline text | 点虚线下划线 | \dotuline{} |
Wavy-Underlined text | 波浪线下划线 | \uwave{} |
Strikethrough text | 删除线 | \sout{} |
Struck with Hatching text | 斜线删除线 | \xout{} |
% Text decorations in Beamer
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% Required package
\usepackage{ulem}\begin{document}\begin{frame}{Text decorations provided by the
\texttt{ulem} package}\uline{Underlined that breaks at the end of lines if
they are too too long because the author won’t stop
writing.} \\~\\\uuline{Double-Underlined text} \\~\\\uwave{Wavy-Underlined text} \\~\\\sout{Strikethrough text} \\~\\\xout{Struck with Hatching text} \\~\\\dashuline{Dashed Underline text} \\~\\ \dotuline{Dotted Underline text} \end{frame}\end{document}
小贴士:你可能注意到每段末尾的
//~//
,这可以在Beamer中创建换行。
2.2.5 有关字体样式设置的四个帖子
这一节教程偷懒了,列了四个另外的单独帖子来让大家学习。
小白后续会将这四个另外的单独课程补上。
- Beamer字体:改变大小、字体族和样式
- 如何改变单页中的字体
- 如何在Beamer中使用极小字体
- 如何修改Beamer中数学公式里的字体风格
2.2.6 改变字体颜色
我们将看到字体颜色是如何提升演讲稿的表现力,吸引观众注意力的。
在LaTeX\LaTeX{}LATEX中使用xcolor包是最简单的设置颜色的方式。该包提供了用于颜色控制的一系列命令。最简单的命令就是\color
,它能让我们在环境中通过颜色的名字来快速设置。
这个命令接受大多数常用颜色名称。这里有一个示例:
% Text color in Beamer
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}\begin{document}\begin{frame}{Colors in beamer}{\color{blue} This is a blue block.}{\color{red} And this is a red one.}\begin{itemize}
\color{green}\item This is a list.\item And it is colored!\end{itemize}
\end{frame}\end{document}
在xcolor包中有一个简单的颜色名称对照,这里小白直接把图搬过来了:
颜色名称的实际列表与所使用的驱动程序有关(什么驱动?显卡的驱动?)例如,你可以使用dvipsnames作为包的选项,使驱动程序dvips的颜色名称可用。有关颜色的名称,请查看这个有趣的教程
2.2.6 高亮文本显示
接下来的示例中,我们将使用一个很有用的命令\textcolor
,来轻松地改变文本的颜色,紧接着使用\colorbox
来高亮部分文本。
% Highlight Text in Beamer
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}\begin{document}\begin{frame}{Highlight text in beamer}\textcolor{red}{This is some colored text}.\\~\\Here I want to \colorbox{yellow}{highlight some
important text in yellow} while leaving the rest
untouched.\end{frame}\end{document}
2.2.6.1 自定义颜色
前面有提过(哪里提过?),你可以自己定义自己的颜色,如果你觉得驱动提供的颜色还不够的话。定义颜色的方式也是由你的驱动器决定的。一般来说,定义颜色的命令为
\definecolor{name}{model}{color definition}
其中,name指的是你将要指定的颜色的名称,model是指用来定义这个颜色的颜色模型,color defintion指的是模型的颜色定义。最常用的颜色模型以及它们的定义语法如下所示;
- rgb: 由三个0-1之间的数,通过逗号分隔,分别代表红、绿、蓝(按顺序)的比例;
- RGB: 与rgb模式类似,只是数值从0-1变成了0-255;
- cmyk: 是由四种颜色的比例数(0-1之间)来确定的,分别是青色、洋红色、黄色和黑色,按顺序以逗号分隔,这种颜色模型适合绝大多数的打印设备;
- gray: 灰度图,用0-1之间的灰阶数表示;
- HTML: 包含6个16进制数字,在HTML代码中表示颜色;
- wave: 通过363-814之间的纳米数,以光波波长表示对应的颜色。
这是创建新颜色更一般和灵活的方法,也许它不是最简单的。
最实用的方法是使用以下的命令:
\colorlet{name}{combination}
其中name是新颜色的名称,combination是已存在颜色的组合。每种颜色的百分比是通过加一个!
来标记:
\colorlet{ochre}{blue!20!yellow!80!}
在接下来的示例中,我们通过这种方法来演示:
% Define colors in Beamer
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% Custom colors
\definecolor{cyanish}{RGB}{10,250,250}
\definecolor{lightgreen}{HTML}{CCFF99}
\definecolor{orangish}{wave}{620}
\colorlet{ochre}{blue!30!yellow!70!}\begin{document}\begin{frame}{Custom colors in beamer}\textcolor{cyanish}{\textbf{This is some cyan text}}\textcolor{lightgreen}{\textbf{This is some lightgreen text}}\textcolor{orangish}{\textbf{This is some orangish text}}\textcolor{ochre}{\textbf{This is some ochre text}}\end{frame}\end{document}
这里创建了四种新颜色,分别通过RGB、HTML、wave和\colorlet
方法。
2.2.7 beamer中的文本对齐
一般在LaTeX\LaTeX{}LATEX文档中,段落是完全对齐的,也就是左右都填满。如果你想要改变对齐方式,LaTeX\LaTeX{}LATEX提供了flushleft, flushright和enter来分别设置左对齐、右对齐和中间对齐模式。
然而,LaTeX\LaTeX{}LATEX环境中没有内建的左右对齐文本,在beamer中,默认地,文本为左对齐。这表明在beamer中没有直接的全对齐方法。直到ragged2e包的诞生,提供了\justifying
命令。这个命令,不管是在frame环境内,或者其他环境内使用,都会将文本设置为两端对齐。
% Text alignment in beamer
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% to generate dummy text
\usepackage{lipsum}% provides the \justifying command
\usepackage{ragged2e}\begin{document}% Default alignment
\begin{frame}{Default beamer alignment}\lipsum[1]
\end{frame}% Flushed right alignment
\begin{frame}{Flushed right}\begin{flushright}\lipsum[2]
\end{flushright}\end{frame}% Centered alignment
\begin{frame}{Centered}
\begin{center}\lipsum[3]
\end{center}
\end{frame}% Fully justified alignment
\begin{frame}{Fully justified}\justifying\lipsum[4]
\end{frame}\end{document}
以下为四个效果:
2.2.8 beamer中的行间距
如果你希望在你的演讲中使用更大的行间距,你需要在文件的序言中使用以下的命令:
\linespread{factor}
但是需要注意的是,这里的factor远非直观。由于TeX\TeX{}TEX的动态特性,\linespread{1.3}
实际代表1.5倍行距,而\linespread{1.6}
则实际代表2倍左右的行距。
% Change line spacing
\documentclass{beamer}% Theme choice
\usetheme{CambridgeUS}% to generate dummy text
\usepackage{lipsum}% Change line spacing
\linespread{1.3}\begin{document}\begin{frame}{Line spacing, linespread with factor 1.3}\lipsum[2]
\end{frame}\end{document}
作为对比,你可以看一下默认行间距的实际情况:
如果你还是对这条命令不满意,可以查看一下setspace这个包,这个包可以对行间距提供更精准的调整。