# Colored blocks for numbered theorems in beamer

Input:

\documentclass{beamer}
\usecolortheme{whale}
\usefonttheme{professionalfonts}

\setbeamertemplate{theorems}[numbered]

\begin{document}

\section{First section}
\begin{frame}
\frametitle{Theorems}
\begin{definition}
Text
\end{definition}
\begin{theorem}
Text
\end{theorem}
\begin{lemma}
Text
\end{lemma}
\begin{theorem}
Text
\end{theorem}
\begin{example}
Text
\end{example}
\end{frame}

\end{document}


Output:

Question: Note that example's blocks are green and all other blocks are blue. How to define a specific color for each kind of block? For example, red for theorems and yellow for definitions. It is important to keep the automatic consecutive numbering.

• If the answer solved your problem, consider accepting it by clicking on the tick mark to help reduce the number of unanswered questions. – Diaa Aug 25 '16 at 20:00
• @DiaaAbidou Accepted! – Pedro Aug 25 '16 at 20:18

This is what you need to put in your preamble

\usepackage{etoolbox}% new package to be loaded
\AtBeginEnvironment{theorem}{% set of commands to be added
\setbeamercolor{block title}{fg=white,bg=orange}% colors to change
\setbeamercolor{block body}{fg=black,bg=yellow}% colors to change
}
\AtBeginEnvironment{proof}{%
\setbeamercolor{block title}{fg=green,bg=red}
\setbeamercolor{block body}{fg=black,bg=purple}

}


## Complete MWE

\documentclass{beamer}
\usecolortheme{whale}
\usefonttheme{professionalfonts}
\usepackage{etoolbox}
\setbeamertemplate{theorems}[numbered]
\AtBeginEnvironment{theorem}{%
\setbeamercolor{block title}{fg=white,bg=orange}
\setbeamercolor{block body}{fg=black,bg=yellow}
}
\AtBeginEnvironment{proof}{%
\setbeamercolor{block title}{fg=green,bg=red}
\setbeamercolor{block body}{fg=black,bg=purple}
}

\setbeamercolor{normal text}{fg=black}

\begin{document}

\section{First section}
\begin{frame}
\frametitle{Theorems}
\begin{proof}
Text
\end{proof}
\begin{definition}
Text
\end{definition}
\begin{theorem}
Text
\end{theorem}
\begin{lemma}
Text
\end{lemma}
\begin{theorem}
Text
\end{theorem}
\begin{example}
Text
\end{example}
\end{frame}

\end{document}


• Thanks, but I found one more problem. The particular block \begin{proof} Text \end{proof} has a automatic blue square inside the text area. The given code \AtBeginEnvironment{proof}... changes the color of the block but doesn't affect the square's color. Is it possible to change the color of that square? – Pedro Aug 25 '16 at 20:10
• @Pedro Modify \setbeamercolor{qed symbol}{fg=orange}, or whatever you like. – samcarter_is_at_topanswers.xyz Aug 25 '16 at 20:14
• @Pedro it worked without problems. Check my update. – Diaa Aug 25 '16 at 20:18