# Creating beamer box environment

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{bodyCol}{fg=white,bg=gray}
Box type \texttt{beamerboxesrounded}\\
Different colours are possible for the header and box contents. \ldots
\end{beamerboxesrounded}
\end{frame}

\end{document}


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?

• It's unclear (maybe only for me) what is your exact question. – bmv Jan 18 '18 at 22:54
• Maybe have a look at the tcolorbox or similar packages. – Dr. Manuel Kuehner Jan 18 '18 at 23:04

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}

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

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

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

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

\end{frame}

\end{document}


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}

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

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

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

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.

I think you are looking for something like this:

\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{bodyCol}{fg=white,bg=gray}

\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}\\
Different colours are possible for the header and box contents. \ldots
\end{examplebox}

\end{frame}

\end{document}


You just need to learn how newenvironment command is used.

Output:

Modifying from the original example seems to be also OK.

\documentclass{beamer}
\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}
`