# Center block on frame with Beamer

I wanted to change the block width in my presentations so, after a quick search on the website, I found the varblock solution : Changing default width of blocks in beamer

\newenvironment<>{varblock}[2][.9\textwidth]{%
\setlength{\textwidth}{#1}
\begin{actionenv}#3%
\def\insertblocktitle{#2}%
\par%
\usebeamertemplate{block begin}}
{\par%
\usebeamertemplate{block end}%
\end{actionenv}}


to the preamble. Now, in my .tex document, I have blocks like this :

\begin{varblock}[8cm]{Title}
Some content...
\end{varblock}


But I cannot center the block horizontally on the frame. I tried to put these three lines between \begin{center}...\end{center} and \begin{centering}...\end{centering} but the block still remains on the left side of the frame. Thanks for your help.

If the shortened block is put inside a minipage, you can center it easily

\documentclass{beamer}
\usetheme{Warsaw}

\newenvironment<>{varblock}[2][.9\textwidth]{%
\setlength{\textwidth}{#1}
\begin{actionenv}#3%
\def\insertblocktitle{#2}%
\par%
\usebeamertemplate{block begin}}
{\par%
\usebeamertemplate{block end}%
\end{actionenv}}

\begin{document}
\begin{frame}
\begin{center}
\begin{minipage}{4cm}
\begin{varblock}[4cm]{New block}
Variable width, here 4cm
\end{varblock}
\end{minipage}
\end{center}
\end{frame}
\end{document}


• Thanks for the solution. I didn't think to put the block inside a minipage! – jibounet May 26 '14 at 17:10
• @Keili Thank you for posting your idea. I rolled back to my original version, because I think, you should post your different approach (an alternative to using a varblock) as an independent answer. – samcarter is at topanswers.xyz Apr 1 '16 at 8:21

If you use minipage as indicated by samcarter, you can use block and omit the varblock definition since minipage already allows for reducing the width of the block:

\documentclass{beamer}
\usetheme{Warsaw}

\begin{document}
\begin{frame}
\begin{center}
\begin{minipage}{4cm}
\begin{block}{New block}
Variable width, here 4cm
\end{block}
\end{minipage}
\end{center}
\end{frame}
\end{document}