[Tex/LaTex] Changing the color of environments in beamer

beamercolorenvironments

I have just started lerning Latex. So, it is possible that the following doubt is very easy.

I have to do a presentation with Beamer. I know that there exist specific comands to theorems, definitions, examples… I wonder if it is possible to modify those environments and change its default color. That is can I use the Theorem environment in such a way that the color of the block is green instead of blue?
In the following example I wanto to change the color of the block to red.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amsmath, amsthm, amssymb}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage[english]{babel}
\usetheme{madrid}
\begin{document}
\begin{frame}{Test}
\begin{theorem}[Pythagoras]
  $a^+b^2=c^2$
\end{theorem}
\end{frame}
\end{document}

enter image description here

Thanks in advance.

Best Answer

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amsmath, amsthm, amssymb}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usetheme{madrid}

\AtBeginEnvironment{theorem}{%
  \setbeamercolor{block title}{use=example text,fg=white,bg=example text.fg!75!black}
  \setbeamercolor{block body}{parent=normal text,use=block title example,bg=block title example.bg!10!bg}
}

\begin{document}
\begin{frame}{Test}
\begin{theorem}[Pythagoras]
  $a^+b^2=c^2$
\end{theorem}
\end{frame}
\end{document}

enter image description here


For a yellow colored "Teorema" block, please see the following MWE:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amsmath, amsthm, amssymb}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usetheme{madrid}

\newtheorem{theo}{Teorema}
\AtBeginEnvironment{theo}{%
  \setbeamercolor{block title}{use=example text,fg=black,bg=yellow!75!black}
  \setbeamercolor{block body}{parent=normal text,use=block title example,bg=yellow!10}
}

\begin{document}
\begin{frame}{Test}
\begin{theo}[Pythagoras]
  $a^+b^2=c^2$
\end{theo}
\end{frame}
\end{document}

enter image description here

Related Question