Beamer简易教学 | 4 文本盒子
 2022年11月15日 09:56
   2022年11月15日 09:56知乎、B站:[易木木响叮当]
关注可了解更多的有限元数值仿真技巧。问题或建议,请公众号留言;
如果你觉得木木同学对你有帮助,欢迎赞赏。
本次分享的主要内容:如何在Beamer中进行文本高亮以及加入文本盒子?
参考资料:
《Beamer快速入门》——黄旭华
颜色列举
xcolor宏包
Beamer默认加载xcolor宏包处理颜色,故不需要额外加载该宏包,可选的颜色有:
dvips 宏包命名的颜色
若大家觉得以上颜色仍不满足,可以加载dvips 宏包来获取更多颜色集,可供选择的颜色如下图所示,调用方式:\documentclass[xcolor=dvipsnames]{beamer} ,注意首字母大写哈~
WinEdt内置
若使用WinEdt编译器进行编译,则可以使用内置颜色快捷工具,屡试不爽!
有色文本
效果
代码片
\begin{frame}{文本盒子}
\textcolor{Salmon}{This text is in Salmon}
\end{frame}
代码解读
-  
   \textcolor{Salmon}{This text is in Salmon}填入颜色代码,即可显示对应的颜色,颜色代码推文开头已给出;
-  
   用户可根据自己喜好来选取喜欢的颜色。 
高亮
效果
代码片
\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}
代码解释
-  
   首先讲一下空行的语句: \bigskip空出大约一行的空间;\medskip空出大约行空间的一半;\smallskip空出大约行空间的四分之一;
-  
   \colorbox{yellow}设置底纹颜色为黄色;\textbf文本加粗,这些语句可以根据自己需求嵌套使用;
-  
   \fcolorbox{red}{yellow}在黄色底纹的基础上设置红色文本框;
-  
   \setlength{\fboxrule}{4pt}边框宽度设置;
-  
   \setlength{\fboxsep}{0pt}设置文本与边框的距离为 0。
块环境
Beamer基于amsmath 宏包内置有一些现成的块环境:theorem、corollary、definition、example、proof,效果非常好,大家请接着往下看:
效果
代码片
\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}
代码解读
-  
   由于是Beamer内置的,所以在中文的编译环境下,显示为对应的块环境标题:定义、定理、证明等; 
-  
   以其中一个块环境为例, \begin{definition}{定义}后面的{定义}将显示在环境里面文本的开头;
-  
   \begin{block}{公众号}...\end{block}在block环境下,环境的标题可以自己指定;
-  
   \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}
代码解读
-  
   umbcboxes 宏包定义了解两个环境:displaybox 和 onlinebox,前者是行间环境,后者是行内环境; 
-  
   \begin{onlinebox}{3cm}设置环境的长度,这个长度需要自己尝试,直到自己满意为止。
-  
   该环境的背景颜色可以进行自己根据喜好需求进行修改,不过大多数情况下,默认的颜色即可。 
本次分享仅限于此了,欢迎大家点赞收藏转发!
谢谢你看完木木同学的分享,今日份阅读花费的流量+1M哈哈哈哈哈哈。
-End-
易木木响叮当
想陪你一起度过短暂且漫长的科研生活
 
 工程师必备
-  项目客服
-  培训客服
-  平台客服
TOP
 
 



















