[Tex/LaTex] Creating beamer box environment

beamer

I could find an example that uses beamer boxes in the book Presentations with LaTeX by Herbert V.

This is the code that I found useful.

\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}

enter image description here

However, I think it's a little bit verbose to have all the commands to get the beamer boxes. So, I think it's convenient to make some environments that help me to make these boxes. For example, I'd like to make some environments to get the same beamer boxes. It would be great if I can give some parameters to the environment. These are possible examples.

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

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

How can I do that? Or, does beamer provide macros to make custom boxes?

Best Answer

Instead of manually fiddling around with the boxes and their parameter, I would simply let beamer do the work for you and use blocks.

Additional advantage: blocks know all the nice beamer features, such as overlays etc.

\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}

enter image description here

If the predefined types of blocks (block, example, alert, theorem, proof ...) are not enough, you could add new ones. Either cheating by adding new theorems or you could define new ones:

\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}

Off-topic and just my personal opinion: I would not mix boxes of different style (e.g. with and without shadow, rounded corner vs. rectangular ones) in the same presentation.

Related Question