# [Tex/LaTex] Center block on frame with Beamer

beamerblock

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}