# How to center all blocks within beamer automatically?

I found a nice solution to change the width of the blocks within my beamer document.

The blocks themselves are aligned left. Is there any opportunity to automatically center each block without putting them into a \begin{center}<block>\end{center} or something like that?

Here is my MWE and how it looks like at the moment:

\documentclass{beamer}

\usetheme{Boadilla}

\addtobeamertemplate{block begin}{%
\setlength{\textwidth}{0.5\textwidth}%
}{}

\begin{document}

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

\end{document}


## 1 Answer

Use

\BeforeBeginEnvironment{block}{\begin{adjustbox}{minipage={\linewidth}, center, , frame}}
\AfterEndEnvironment{block}{\end{adjustbox}}


The frame is just to let you see what happens. The commands will place the block in a minipage then center it. The white space above the block means that the block environment automatically inserts an empty space above itself.

Full code

\documentclass{beamer}

\usetheme{Boadilla}

\addtobeamertemplate{block begin}{%
\centering%
\setlength{\textwidth}{0.5\textwidth}%
}{}

\BeforeBeginEnvironment{block}{\begin{adjustbox}{minipage={\linewidth}, center, frame}}
\AfterEndEnvironment{block}{\end{adjustbox}}

\usepackage{adjustbox}

\begin{document}

\begin{frame}

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

\end{frame}

\end{document}