3

I have noticed that, inside beamercolorbox, the enumerate environment does not respect -- i.e., completely ignores -- the sep parameter. Here is a minimal example:

\documentclass{beamer}
\setbeamercolor{box}{fg=black,bg=gray!30}

\begin{document}

\begin{frame}

\begin{beamercolorbox}[sep=30pt]{box}
Some text in a beamercolorbox with parameter sep=30pt. The text is separated 30 pt from the border of the box, as expected. Now comes an enumeration:
\begin{enumerate}
\item First list item. First list item. First list item. First list item. First list item.  
\item Second list item. Second list item. Second list item. Second list item. Second list item. 
\end{enumerate}
As can be seen, the enumeration is \emph{not} separated 30 pt from the border of the box.
\end{beamercolorbox}

\end{frame}

\end{document}

enter image description here

Is this a bug? Or is it expected behavior? In any case, how to I get around it, i.e., have an enumeration inside a colored box that has the same separation from the border of the box as the normal text?

Thanks in advance for your help!

1 Answer 1

3

New attempt

  • My first attempt directly patches the list environment.
  • This new attempt patches beamercolorbox by updating the line width used by list environments. Note that beamercolorbox adds the value passed to sep option to \leftskip and \rightskip, but the line width is not updated.
% put these lines in preamble
\usepackage{xpatch}

\makeatletter
% originally defined in beamerbasecolor.sty
\xpatchcmd\beamercolorbox
  {%
    \leftskip=\beamer@colbox@ls%
    \ifdim\beamer@colbox@sep>\z@\advance\leftskip\beamer@colbox@sep\fi%
    \rightskip=\beamer@colbox@rs%
    \ifdim\beamer@colbox@sep>\z@\advance\rightskip\beamer@colbox@sep\fi
  }
  {%
    \leftskip=\beamer@colbox@ls%
    \ifdim\beamer@colbox@sep>\z@
      \advance\leftskip\beamer@colbox@sep
      \advance\linewidth-\beamer@colbox@sep       % added
      \advance\@totalleftmargin\beamer@colbox@sep % added
    \fi%
    \rightskip=\beamer@colbox@rs%
    \ifdim\beamer@colbox@sep>\z@
      \advance\rightskip\beamer@colbox@sep
      \advance\linewidth-\beamer@colbox@sep       % added
    \fi
  }
  {}{\fail}
\makeatother

Variant for beamer v3.36, which is used by OP

% put these lines in preamble
\usepackage{xpatch}

% originally defined in beamerbasecolor.sty, beamer v3.36
% see https://github.com/josephwright/beamer/blob/v3.36/base/beamerbasecolor.sty
\makeatletter
\xpatchcmd\beamercolorbox
  {%
    \leftskip=\beamer@colbox@ls%
    \advance\leftskip by\beamer@colbox@sep%
    \rightskip=\beamer@colbox@rs%
    \advance\rightskip by\beamer@colbox@sep
  }
  {%
    \leftskip=\beamer@colbox@ls%
    \ifdim\beamer@colbox@sep>\z@
      \advance\leftskip\beamer@colbox@sep
      \advance\linewidth-\beamer@colbox@sep       % added
      \advance\@totalleftmargin\beamer@colbox@sep % added
    \fi%
    \rightskip=\beamer@colbox@rs%
    \ifdim\beamer@colbox@sep>\z@
      \advance\rightskip\beamer@colbox@sep
      \advance\linewidth-\beamer@colbox@sep       % added
    \fi
  }
  {}{\fail}
\makeatother

First attempt

\documentclass{beamer}
\setbeamercolor{box}{fg=black,bg=gray!30}

\makeatletter
\patchcmd\beamer@enum@
  {\usecounter\@enumctr}
  {%
    \usecounter\@enumctr
    % patch into the second argument of \list
    % here \beamer@colbox@sep stores the value passed to option sep
    \addtolength{\leftmargin}{\beamer@colbox@sep}%
    \addtolength{\rightmargin}{\beamer@colbox@sep}%
  }
  {}{\fail}
\makeatother


\begin{document}

\begin{frame}
  \begin{beamercolorbox}[sep=30pt]{box}
    Some text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
    \begin{enumerate}
      \item First list item. First list item. First list item. First list item. First list item.  
      \item Second list item. Second list item. Second list item. Second list item. Second list item. 
    \end{enumerate}
    As can be seen, the enumeration is \emph{not} separated 30 pt from the border of the box.
  \end{beamercolorbox}
\end{frame}

\end{document}

enter image description here

Update to first attempt

This further example contains the similar patches for itemize and description environments as well.

  • Because of how \itemized is defined, we need \xpatchcmd from xpatch package to do the patching. Hence I replaced all \patchcmd by \xpatchcmd.
\documentclass{beamer}
\setbeamercolor{box}{fg=black,bg=gray!30}
\usepackage{xpatch}

\makeatletter
% patch enumerate
\xpatchcmd\beamer@enum@
  {\usecounter\@enumctr}
  {%
    \usecounter\@enumctr
    % patch into the second argument of \list
    % here \beamer@colbox@sep stores the value passed to option sep
    \addtolength{\leftmargin}{\beamer@colbox@sep}%
    \addtolength{\rightmargin}{\beamer@colbox@sep}%
  }
  {}{\fail}

% patch itemize
\xpatchcmd\itemize
  {\def\makelabel}
  {%
    \addtolength{\leftmargin}{\beamer@colbox@sep}%
    \addtolength{\rightmargin}{\beamer@colbox@sep}%
    \def\makelabel
  }
  {}{\fail}

% patch description
\xpatchcmd\@@description
  {\let\makelabel\beamer@descriptionitem}
  {%
    \let\makelabel\beamer@descriptionitem
    \addtolength{\leftmargin}{\beamer@colbox@sep}%
    \addtolength{\rightmargin}{\beamer@colbox@sep}%
  }
  {}{\fail}
\makeatother


\begin{document}

\begin{frame}
  \begin{beamercolorbox}[sep=30pt]{box}
    Some text text text text text text text text text text text text text text
    \begin{enumerate}
      \item First list item. First list item. First list item. First list item. First list item.  
      \item Second list item. Second list item. Second list item. Second list item. Second list item. 
    \end{enumerate}
    As can be seen, the enumeration is now separated 30pt from the border of the box.
  \end{beamercolorbox}
\end{frame}

\begin{frame}
  \begin{beamercolorbox}[sep=30pt]{box}
    Some text text text text text text text text text text text text text text
    \begin{itemize}
      \item First list item. First list item. First list item. First list item. First list item.  
      \item Second list item. Second list item. Second list item. Second list item. Second list item. 
    \end{itemize}
    As can be seen, the itemize is now separated 30pt from the border of the box.
  \end{beamercolorbox}
\end{frame}

\begin{frame}
  \begin{beamercolorbox}[sep=30pt]{box}
    Some text text text text text text text text text text text text text text
    \begin{description}[longest text]
      \item[text] First list item. First list item. First list item.
      \item[longest text] Second list item. Second list item. Second list item.
      \item[more text] Another list item
    \end{description}
    As can be seen, the description is now separated 30pt from the border of the box.
  \end{beamercolorbox}
\end{frame}

\end{document}

enter image description here enter image description here

14
  • 1
    @Wolfhart \patchcmd is from etoolbox package. But etoolbox is already loaded by beamer. What version of beamer are you using? Commented May 22, 2020 at 3:40
  • 1
    @Wolfhart Yes. You are using TeX Live 2015 and the latest is TeX Live 2020. So manually loading etoolbox maybe required. Commented May 22, 2020 at 6:52
  • 1
    @Wolfhart Response to question 1: You can redefine the \itemize based on the its definition in beamerbaselocalstructure.sty, and insert \addtolength ... staff in the second argument of \list used inside \itemize. Commented May 22, 2020 at 15:44
  • 1
    @Wolfhart Response to question 2: It can be seen as a bug. I have just opened two issues to report this to and open further discussions on beamer, see github.com/josephwright/beamer/issues/605 and github.com/josephwright/beamer/issues/606. Commented May 22, 2020 at 16:14
  • 1
    @Wolfhart I've updated my answer, the newly added example contains similar patches for both itemize and description. Commented May 23, 2020 at 4:36

You must log in to answer this question.

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