Define a new block environment in LaTeX beamer

I have two kinds of examples in my document. I want to use different colors, say, red and blue. This is what I am doing now.

\documentclass[]{beamer}
\begin{document}

\begin{frame}
\frametitle{Test}
\setbeamercolor{block title}{fg=white,bg=red!75!black}
\begin{block}{First Kind Example}
This is example of the first kind.
\end{block}
\setbeamercolor{block title}{fg=white,bg=blue!75!black}
\begin{block}{Second Kind Example}
This is example of the second kind.
\end{block}
\end{frame}

\end{document}


I know this is kind of stupid. I want to define two new block environments, one for each color, so I don't need to use setbeamercolor every time I use them.

\begin{block1}{First Kind Example}
...
\end{block1}
\begin{block2}{Second Kind Example}
...
\end{block2}


I know I need to define these two new environments in the preamble, but don't know how. Thanks for the help.

By the way, what is a good reference on these kinds of tricks in LaTeX/beamer? Any recommendations?

If you want to present them as examples and mark them up as such using beamer's example environment (rather than just using the generic block) you might try something like this:

\documentclass[]{beamer}

\newtheorem{examplefirst}{Example}
\newtheorem{examplesecond}{Example}
\newenvironment<>{examplefirst}[1][]{%
\setbeamercolor{block title example}{fg=white,bg=red!75!black}%
\begin{example}#2[#1]}{\end{example}}
\newenvironment<>{examplesecond}[1][]{%
\setbeamercolor{block title example}{fg=white,bg=blue!75!black}%
\begin{example}#2[#1]}{\end{example}}

\begin{document}

\begin{frame}
\begin{examplefirst}[An example of the first kind]
\end{examplefirst}
\begin{examplesecond}[An example of the second kind]
\end{examplesecond}
\begin{example}[A regular example]
\end{example}
\end{frame}

\end{document}


which produces:

If you prefer to stick to the generic block environment perhaps something like this might work:

\documentclass[]{beamer}

\newenvironment<>{examplefirst}[1]{%
\setbeamercolor{block title}{fg=white,bg=red!75!black}%
\begin{block}#2{#1}}{\end{block}}
\newenvironment<>{examplesecond}[1]{%
\setbeamercolor{block title}{fg=white,bg=blue!75!black}%
\begin{block}#2{#1}}{\end{block}}

\begin{document}

\begin{frame}
\begin{examplefirst}{An example of the first kind}
\end{examplefirst}
\begin{examplesecond}{An example of the second kind}
\end{examplesecond}
\begin{block}{A regular block}
Something in the regular block format.
\end{block}
\end{frame}

\end{document}


• @cfr, Could you explain you command for new environment? For example, what are <> for? – Royi Jun 4 '17 at 22:27
• @Royi It makes the environment overlay-specification-aware. See Beamer's manual for details - it changes \newcommand and \newenvironment and friends in this way. – cfr Jun 5 '17 at 1:02
• May I also ask how come you use #2 while you define only 1 parameter for the environment? Thank You. – Royi Jun 5 '17 at 18:07
• @Royi That's for the overlay specification. – cfr Jun 5 '17 at 21:12

Here you have the standard code, using different colors

\documentclass{beamer}

\usecolortheme{whale}
\usecolortheme{orchid}

\begin{document}

\begin{frame}{A frame}

\begin{block}{A block environment}
Some text.
\end{block}

Some text.

• Excellent! You can start with the manual, looking section 12.3 Block Environments and how to change the templates' aspect via \setbeamercolor. +1 meanwhile :) – Claudio Fiandrino Jan 5 '14 at 18:19