1

The code below redefines beamer's default block environment to allow for style customizations. Unfortunately it somehow also changes the horizontal spacing of the last column (the rule of the third column should fill the remaining space to match the right border of the top rule). If one skips the \RenewDocumentEnvironment call everything is fine. What's the reason for this space and how to properly redefine the blocks? (Parts of the source and the idea to redefine it like that might come form SE but I can't find the original code).

\documentclass[english]{beamer}

\usepackage{xparse}

% Save old block environment commands (with LetLtxMacro to support arguments)
\LetLtxMacro\origblock\block
\LetLtxMacro\endorigblock\endblock

% Introduce a new block whose title and body format can be customized
\newenvironment{formattedblock}[3]%
{%
  % Force expansion of the second setbeamercolor argument by using edef
  \edef\settitleformat{\noexpand\setbeamercolor{block title}{#2}}%
  \settitleformat%
  \edef\setbodyformat{\noexpand\setbeamercolor{block body}{#3}}%
  \setbodyformat%
  \begin{origblock}{#1}%
}{%
  \end{origblock}%
}

% Reformat ordinary blocks by using this formattedblock config
\RenewDocumentEnvironment{block}{ g }%
{%
  \begin{formattedblock}{#1}{bg=blue,fg=white}{bg=gray,fg=black}%
}{%
  \end{formattedblock}%
}


\begin{document}

  \begin{frame}[t]{}
    \rule{\linewidth}{1ex}
    \begin{columns}[onlytextwidth,t]

      \begin{column}{0.25\linewidth}
        \rule{\linewidth}{1ex}
        \begin{block}{foo}
          bar
        \end{block}
      \end{column}

      \begin{column}{0.25\linewidth}
        \rule{\linewidth}{1ex}
        \begin{block}{foo}
          bar
        \end{block}
      \end{column}

      \begin{column}{0.25\linewidth}
        \rule{\linewidth}{1ex}
        \begin{block}{foo}
          \begin{itemize}
            \setbeamertemplate{itemize item}[circle]
            \item bar
          \end{itemize}
        \end{block}
      \end{column}

    \end{columns}
  \end{frame}
\end{document}

The following screenshots show the output once with the error (if the \RenewDocumentEnvironment is enabled) and once without the space (and formatting), respectively.

fail ok

Edit #2:

Interestingly, the same effect can be produced by simply styling the blocks with the traditional beamer commands:

\setbeamercolor{block title}{bg=blue,fg=white}
\setbeamercolor{block body}{bg=gray,fg=black}

So this is not related to the environment redefinition at all. The question still remains: why does this happen?

Edit #3: Apparently beamer does this if you define any background color. Duh. As of Beamer 3.40 this is not mentioned or explained in the manual AFAICT.

  • I have read the question backward and forward, and uncommented the \RenewDocumentEnvironment or left it in, and always get the same layout of the rules. Could you please attach screen shots of what you get, and indicate what your concern is. (May it be that you only need to update your TeX installation?) – user121799 Jul 9 at 5:17
  • Interesting. I have tested this with Debian's texlive 2016.20170123-5 and overleaf (which as of now might be the same thing unfortunately :) Screenshots attached to the questions. – stefanct Jul 9 at 10:25
  • I only get the lower screen shot regardless of whether or not I comment \RenewDocumentEnvironment. I am using pdflatex on a TeXLive 2019 distribution. – user121799 Jul 9 at 11:46
1

The most likely cause of additional space around beamer blocks is that it's using a beamercolorbox with colsep*=0.75ex and some background color is set. The colsep option is explained in the manual in the section on beamercolorbox options:

colsep*=⟨dimension⟩ sets an extra color separation space around the text that is horizontally outside the box. This means that if the box has a background, this background will protrude by ⟨dimension⟩ to the left and right of the text, but this protruding background will not be taken into consideration by TEX for typesetting purposes.

So, if you don't need the background colors, simply unset the bg values else you will have to redefine the block environment completely as explained here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.