17

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

It consists in adding :

\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.

3 Answers 3

14

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

\documentclass{beamer}
\usetheme{Warsaw}

\newenvironment<>{varblock}[2][.9\textwidth]{%
    \begin{minipage}{#1}
    \begin{actionenv}#3%
        \def\insertblocktitle{#2}%
        \par%
        \usebeamertemplate{block begin}}
    {\par%
        \usebeamertemplate{block end}%
    \end{actionenv}
    \end{minipage}}
    
\begin{document}
    \begin{frame}
        \begin{center}
                \begin{varblock}[4cm]{New block}
                    Variable width, here 4cm
                \end{varblock}
        \end{center}
    \end{frame}
\end{document}

enter image description here


Another possibility is to use the tcolorbox inner beamer theme and then redefine your varblock using a tcolorbox:

\documentclass{beamer}
\usetheme{Warsaw}

\useinnertheme{tcolorbox}
\newtcolorbox{varblock}[2][.9\textwidth]{width=#1,title=#2,center}

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

enter image description here

4
  • Thanks for the solution. I didn't think to put the block inside a minipage!
    – pitchounet
    Commented May 26, 2014 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. Commented Apr 1, 2016 at 8:21
  • The dark corners of LaTeX. Such a basic and trivial feature, yet so complicated and non intuitive to implement...
    – luchonacho
    Commented May 14 at 13:36
  • @luchonacho It's just a matter of using the right tool for the job. Commented May 14 at 14:10
15

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}
0
1

It might be related to my theme, but the minipage environment is messing with the space between the block header and block body. Putting it in columns solved this issue for me:

\documentclass{beamer}
\usetheme{Warsaw}

\begin{document}
  \begin{frame}
    \begin{columns}[T]
      \column{0.25\textwidth}
      \column{0.5\textwidth}
      \begin{block}{New block}
         Variable width, here 50%
      \end{block}
    \column{0.25\textwidth}
    \end{columns}
  \end{frame}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .