[Tex/LaTex] Redefine block template for Beamer theorem-like environment

beamertheorems

I would like to redefine the block templates for Beamer's theorem-like environments. For example, the example environment creates an exampleblock. I would like to make the definition environment do the same thing.

It's possible to do this locally using the exampleblock environment:

\begin{exampleblock}{Definition}
(Definition here)
\end{exampleblock}

However, I would like a global solution.

I should add that much the same question was asked on Stackoverflow, but no one seems to have figured out a solution.

Best Answer

You can set the theorem begin and theorem end templates to use an exampleblock:

\documentclass{beamer}
\usetheme{CambridgeUS}

\makeatletter
\setbeamertemplate{theorem begin}
{%
  \begin{exampleblock}
  {%
%    \inserttheoremheadfont% uncomment if you want amsthm-like formatting
    \inserttheoremname
    \inserttheoremnumber
    \ifx\inserttheoremaddition\@empty\else\ (\inserttheoremaddition)\fi%
    \inserttheorempunctuation
  }%
}
\setbeamertemplate{theorem end}{\end{exampleblock}}
\makeatother

\begin{document}

\begin{frame}
\begin{definition}
Test text.
\end{definition}
\begin{exampleblock}{Definition}
(Definition here)
\end{exampleblock}
\end{frame}

\end{document}

enter image description here

The above solution makes all theorem-like environments inherit the settings for exampleblock; if just the default definition environment must behave like exampleblock, all one has to do is to change the default style used for definition to make it equal to the example style; a simple way to achieve this is to \let both commands \definition and \enddefinition to \relax and then use \newtheorem to define the definition structure using the example style.

An example showing this approach; definition behaves as an exampleblock, but all other theorem-like structures preserve theis default behaviour:

\documentclass{beamer}
\usetheme{CambridgeUS}

\let\definition\relax
\let\enddefinition\relax

\theoremstyle{example}
\newtheorem{definition}[theorem]{\translate{Definition}}

\begin{document}

\begin{frame}
\begin{definition}
Test text.
\end{definition}
\begin{exampleblock}{Definition}
Test text.
\end{exampleblock}
\begin{theorem}
Test text.
\end{theorem}
\end{frame}

\end{document}

enter image description here