Beamer簡易教學 | 4 文本盒子

知乎、B站[易木木響叮當]
關注可了解更多的有限元數值仿真技巧。問題或建議,請公眾號留言;
如果你覺得木木同學對你有幫助,歡迎贊賞。

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

參考資料:

《Beamer快速入門》——黃旭華


顏色列舉

xcolor宏包

Beamer默認加載xcolor宏包處理顏色,故不需要額外加載該宏包,可選的顏色有:

Beamer簡易教學 | 4 文本盒子的圖1
xcolor顏色

dvips 宏包命名的顏色

若大家覺得以上顏色仍不滿足,可以加載dvips 宏包來獲取更多顏色集,可供選擇的顏色如下圖所示,調用方式:\documentclass[xcolor=dvipsnames]{beamer} ,注意首字母大寫哈~

Beamer簡易教學 | 4 文本盒子的圖2
dcips顏色

WinEdt內置

若使用WinEdt編譯器進行編譯,則可以使用內置顏色快捷工具,屢試不爽!

Beamer簡易教學 | 4 文本盒子的圖3
WinEdt內置顏色

有色文本

效果

Beamer簡易教學 | 4 文本盒子的圖4
有色文本

代碼片

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

代碼解讀

  1. \textcolor{Salmon}{This text is in Salmon}填入顏色代碼,即可顯示對應的顏色,顏色代碼推文開頭已給出;

  2. 用戶可根據自己喜好來選取喜歡的顏色。

高亮

效果

Beamer簡易教學 | 4 文本盒子的圖5
高亮顯示

代碼片

\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,效果非常好,大家請接著往下看:

效果

Beamer簡易教學 | 4 文本盒子的圖6
塊環境1
Beamer簡易教學 | 4 文本盒子的圖7
塊環境2

代碼片

\begin{frame}{文本盒子}

\begin{definition}{定義}
A triangle that has a right angle is called
\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
\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即可自動獲取,使用時,將該宏包放置在當前目錄下即可。

效果

Beamer簡易教學 | 4 文本盒子的圖8
行間文本盒子
Beamer簡易教學 | 4 文本盒子的圖9
行內文本盒子

代碼片

\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. 該環境的背景顏色可以進行自己根據喜好需求進行修改,不過大多數情況下,默認的顏色即可。


本次分享僅限于此了,歡迎大家點贊收藏轉發!


謝謝你看完木木同學的分享,今日份閱讀花費的流量+1M哈哈哈哈哈哈Beamer簡易教學 | 4 文本盒子的圖10



-End-


易木木響叮當

想陪你一起度過短暫且漫長的科研生活


登錄后免費查看全文
立即登錄
App下載
技術鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP