创建 Beamer Box 环境

创建 Beamer Box 环境

我可以在 Herbert V 所著的 Presentations with LaTeX 一书中找到一个使用 beamer boxes 的示例。

这是我发现有用的代码。

\documentclass{beamer}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{frame}{Examples for boxes}

% box1
\setbeamercolor{BoxColour}{fg=white,bg=blue!60}
\begin{beamercolorbox}[sep=1em,wd=5cm]{BoxColour}
   The \texttt{beamercolorbox} environment!
\end{beamercolorbox}\medskip

% box2
\setbeamercolor{headerCol}{fg=black,bg=lightgray}
\setbeamercolor{bodyCol}{fg=white,bg=gray}
\begin{beamerboxesrounded}[upper=headerCol,lower=bodyCol,shadow=true]{Example}
 Box type \texttt{beamerboxesrounded}\\
 with shadow.\\
 Different colours are possible for the header and box contents. \ldots
\end{beamerboxesrounded}
\end{frame}

\end{document}

在此处输入图片描述

但是,我认为列出获取投影仪盒的所有命令有点冗长。因此,我认为创建一些有助于我创建这些盒的环境会很方便。例如,我想创建一些环境来获取相同的投影仪盒。如果我可以为环境提供一些参数就太好了。这些是可能的例子。

\begin{flatbox}[fg=yellow]
    The \texttt{beamercolorbox} environment!
\end{flatbox}

\begin{examplebox}
   Box type \texttt{beamerboxesrounded}\\
   ...
\end{examplebox}

我该怎么做?或者,Beamer 是否提供宏来制作自定义框?

答案1

我不需要手动摆弄盒子及其参数,而是直接让 beamer 为您完成工作并使用块。

额外优势:block了解所有优秀的投影仪功能,例如覆盖等。

\documentclass{beamer}

\useinnertheme[shadow]{rounded}
\setbeamercolor{block title example}{fg=black,bg=lightgray}
\setbeamercolor{block body example}{fg=white,bg=gray}
\setbeamercolor{block body}{fg=white,bg=blue!60}

\begin{document}

\begin{frame}

\begin{minipage}{5cm}
\setbeamertemplate{block begin}[default]
\setbeamertemplate{block end}[default]
\begin{block}{}
    The \texttt{beamercolorbox} environment!
\end{block}
\end{minipage}

\begin{exampleblock}{block title}
 Box type \texttt{beamerboxesrounded}

 with shadow.

 Different colours are possible for the header and box contents. \ldots
\end{exampleblock}

\begin{example}
 Box type \texttt{beamerboxesrounded}

 with shadow.

 Different colours are possible for the header and box contents. \ldots
\end{example}

\end{frame}

\end{document}

在此处输入图片描述

如果预定义的块类型(块、示例、警报、定理、证明...)不够,您可以添加新的块。要么通过添加新定理来作弊,要么定义新的定理:

\documentclass{beamer}

\useinnertheme[shadow]{rounded}
\setbeamercolor{block title example}{fg=black,bg=lightgray}
\setbeamercolor{block body example}{fg=white,bg=gray}
\setbeamercolor{block body}{fg=white,bg=blue!60}

  \newenvironment<>{prosseekblock}[1]{%
    \begin{actionenv}#2%
      \def\insertblocktitle{#1}%
      \par%
      \mode<presentation>{%\usebeamerfont{block}%
        \setbeamercolor{local structure}{parent=example text}}%
      \usebeamertemplate{block prosseek begin}}
    {\par%
      \usebeamertemplate{block prosseek end}%
    \end{actionenv}}    

\defbeamertemplate*{block prosseek end}{default}
{\end{beamercolorbox}\vskip\smallskipamount}


\defbeamertemplate*{block prosseek begin}{default}
{
  \par\vskip\medskipamount%
  \begin{beamercolorbox}[colsep*=.75ex]{block title example}
    \usebeamerfont*{block title example}\insertblocktitle%
  \end{beamercolorbox}%
  {\parskip0pt\par}%
  \ifbeamercolorempty[bg]{block title example}
  {}
  {\ifbeamercolorempty[bg]{block body example}{}{\nointerlineskip\vskip-0.5pt}}%
  \usebeamerfont{block body example}%
  \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body example}%
    \ifbeamercolorempty[bg]{block body example}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}


\begin{document}

\begin{frame}

\begin{minipage}{5cm}
\setbeamertemplate{block begin}[default]
\setbeamertemplate{block end}[default]
\begin{block}{}
    The \texttt{beamercolorbox} environment!
\end{block}
\end{minipage}

\begin{exampleblock}{block title}
 Box type \texttt{beamerboxesrounded}

 with shadow.

 Different colours are possible for the header and box contents. \ldots
\end{exampleblock}

\begin{example}
 Box type \texttt{beamerboxesrounded}

 with shadow.

 Different colours are possible for the header and box contents. \ldots
\end{example}

\begin{prosseekblock}{test}
    test
\end{prosseekblock}

\end{frame}

\end{document}

题外话,仅代表我的个人观点:我不会在同一个演示文稿中混合不同风格的框(例如有阴影和无阴影,圆角和矩形)。

答案2

我认为你正在寻找这样的东西:

\documentclass{beamer}
\usepackage[utf8]{inputenc}

\setbeamercolor{firb}{fg=orange,bg=gray}
\setbeamercolor{secb}{fg=yellow,bg=blue}


\newenvironment{flatbox}[1]{\begin{beamercolorbox}[sep=1em,wd=5cm]{#1}}{\end{beamercolorbox}}


\setbeamercolor{headerCol}{fg=black,bg=lightgray}
\setbeamercolor{bodyCol}{fg=white,bg=gray}


\newenvironment{examplebox}[1][upper=headerCol,lower=bodyCol,shadow=true]{\begin{beamerboxesrounded}[#1]{Example}}{\end{beamerboxesrounded}}


\begin{document}
\begin{frame}{Examples for boxes}

% box1
\begin{flatbox}{secb}
  The test first box
  \end{flatbox}


\begin{flatbox}{firb}
  Second test
  \end{flatbox}

% box2
\begin{examplebox}
   Box type \texttt{beamerboxesrounded}\\
 with shadow.\\
 Different colours are possible for the header and box contents. \ldots
\end{examplebox}

\end{frame}

\end{document}

您只需要了解如何使用 newenvironment 命令。

输出:

在此处输入图片描述

答案3

从原始示例进行修改似乎也可以。

\documentclass{beamer}
\useinnertheme[shadow]{rounded}
\setbeamercolor{background canvas}{bg=yellow}

\newtheorem{Discussion}{Example}

% discussion 
\newenvironment<>{Discussion}[2][]{%
  \setbeamercolor{block title example}{fg=white,bg=red!75!black}%
  \setbeamercolor{block body example}{fg=black,bg=white!70!red}%
  \begin{exampleblock}{`D': #2}}{\end{exampleblock}}

\begin{document}

\begin{frame}

\begin{Discussion}{Discussion?}
Let's discuss    
\end{Discussion}

\begin{Example}{Example}
Example    
\end{Example}

\end{frame}

\end{document} 

在此处输入图片描述

相关内容