[Tex/LaTex] How to Center a BeamerColorBox

beamerhorizontal alignment

The question is, how to horizontally center a beamercolorbox on the page?

I put it in the center environment, but that doesn't work.

\setbeamercolor{bgcolor}{fg=black,bg=blue}
\begin{center}
    \begin{beamercolorbox}[rounded=true, center=true, shadow=true, wd=6cm]{bgcolor}
        Some text goes here...
    \end{beamercolorbox}
\end{center}

Best Answer

wd=<dimen> not only sets the width of the beamercolorbox to <dimen>, it sets the \hsize to <dimen>. So you're centering a box in a line which has the same width as the box, resulting in nothing.

So to force centering, use some \hfills:

\documentclass{beamer}
\setbeamercolor{bgcolor}{fg=black,bg=blue}

\begin{document}

\begin{frame}
\hfill
    \begin{beamercolorbox}[rounded=true, center, shadow=true,wd=6cm]{bgcolor}
        Some text goes here...
    \end{beamercolorbox}
\hfill\hfill
\end{frame}

\end{document}

I'm not sure why you need two at the end—it seems like one at the front and back would do the centering. But instead you just get a box flush right. So an extra one does the trick.