Beamer简易教学 | 4 文本盒子

本次分享的主要内容:如何在Beamer中进行文本高亮以及加入文本盒子? 

 

参考资料:

《Beamer快速入门》——黄旭华


颜色列举

xcolor宏包

Beamer默认加载xcolor宏包处理颜色,故不需要额外加载该宏包,可选的颜色有:

xcolor颜色

dvips 宏包命名的颜色

若大家觉得以上颜色仍不满足,可以加载dvips 宏包来获取更多颜色集,可供选择的颜色如下图所示,调用方式:\documentclass[xcolor=dvipsnames]{beamer} ,注意首字母大写哈~

dcips颜色

WinEdt内置

若使用WinEdt编译器进行编译,则可以使用内置颜色快捷工具,屡试不爽!

WinEdt内置颜色

有色文本

效果

有色文本

代码片 

 

\begin{frame}{文本盒子}
\textcolor{Salmon}{This text is in Salmon}
\end{frame}

 

代码解读

  1. \textcolor{Salmon}{This text is in Salmon}填入颜色代码,即可显示对应的颜色,颜色代码推文开头已给出;

  2. 用户可根据自己喜好来选取喜欢的颜色。

高亮

效果

高亮显示

代码片

\begin{frame}{文本盒子}

\colorbox{yellow}{This text is highlighted in yellow} 
\bigskip

\colorbox{yellow}{ 
    \textcolor{red}{ 
        \textbf{ 
            Bold text in red, highlighted in yellow 
        } 
    } 
} 
\bigskip

 \fcolorbox{red}{yellow}{A yellow box with red border} 
\bigskip

 \setlength{\fboxrule}{4pt} 
\fcolorbox{red}{white}{A white box with a red border of thickness 4 points} 
\bigskip

\setlength{\fboxrule}{4pt} 
\setlength{\fboxsep}{0pt} 
\fcolorbox{red}{white}{A white box with a red border and separation of 0 points}

\end{frame}

代码解释

  1. 首先讲一下空行的语句:\bigskip空出大约一行的空间;\medskip空出大约行空间的一半;\smallskip空出大约行空间的四分之一;

  2. \colorbox{yellow} 设置底纹颜色为黄色; \textbf文本加粗,这些语句可以根据自己需求嵌套使用;

  3. \fcolorbox{red}{yellow}在黄色底纹的基础上设置红色文本框;

  4. \setlength{\fboxrule}{4pt}边框宽度设置;

  5. \setlength{\fboxsep}{0pt} 设置文本与边框的距离为 0。

块环境

Beamer基于amsmath 宏包内置有一些现成的块环境:theorem、corollary、definition、example、proof,效果非常好,大家请接着往下看:

效果

块环境1

块环境2

代码片

\begin{frame}{文本盒子}

\begin{definition}{定义}
A triangle that has a right angle is called
a \emph{right triangle}.
\end{definition}

\begin{theorem}{定理}
  In a right triangle, the square of hypotenuse equals
  the sum of squares of two other sides.
\end{theorem}

\begin{proof}{证明}
  We leave the proof as an exercise to our astute reader.
  We also suggest that the reader generalize the proof to
  non-Euclidean geometries.
\end{proof}

\end{frame}

\begin{frame}{文本盒子}

\begin{corollary}{推论}
A triangle that has a right angle is called
a right triangle.
\end{corollary}

\begin{example}{例1}
A triangle that has a right angle is called
a \emph{right triangle}.
\end{example}

\begin{block}{公众号}
   \centerline{易木木响叮当} 
\end{block}  

\end{frame}

代码解读

  1. 由于是Beamer内置的,所以在中文的编译环境下,显示为对应的块环境标题:定义、定理、证明等;

  2. 以其中一个块环境为例,\begin{definition}{定义}后面的{定义}将显示在环境里面文本的开头;

  3. \begin{block}{公众号}...\end{block}block环境下,环境的标题可以自己指定;

  4. \centerline{易木木响叮当}将文本居中在该行显示。

文本盒子

umbcboxes 宏包可以将文本和方程式放在精美的圆角带阴影的盒子中,如下图所示,我已将该宏包打包在资源里面,后台回复Beamer即可自动获取,使用时,将该宏包放置在当前目录下即可。

效果

行间文本盒子

行内文本盒子

代码片

\begin{frame}{Fancy boxes}

The displaybox environment is suitable for boxing
displayed mathematics:
\begin{displaybox}{4cm}
\[
    \sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}
\]
\end{displaybox}
\bigskip

The body of the environment can be anything.  For example:
\begin{displaybox}{5cm}
This is a test.
\end{displaybox}
\bigskip

Centered text may look better:
\begin{displaybox}{5cm}
\centerline{This is a test.}
\end{displaybox}

\end{frame}

\begin{frame}{Fancy boxes (continued)}

The onlinebox environment is similar to displaybox,
but it puts the boxed material within the current line
\begin{onlinebox}{2cm} like this.\end{onlinebox}
Box contents are automatically centered.
\bigskip

The body of an onlinebox may contain mathematics.  As in this
\begin{onlinebox}{3cm}
$\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}$
\end{onlinebox} example.
\bigskip

To get display-style mathematics
\begin{onlinebox}{3cm}
$\displaystyle \sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}$
\end{onlinebox}
add the \textsl{$\backslash$displaystyle} command to your formula.

\end{frame}

代码解读

  1. umbcboxes 宏包定义了解两个环境:displayboxonlinebox,前者是行间环境,后者是行内环境;

  2. \begin{onlinebox}{3cm}设置环境的长度,这个长度需要自己尝试,直到自己满意为止。

  3. 该环境的背景颜色可以进行自己根据喜好需求进行修改,不过大多数情况下,默认的颜色即可。


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

易木木木响叮当

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值