Beamer:在 beamercolorbox 内部,枚举不尊重 sep 参数

Beamer:在 beamercolorbox 内部,枚举不尊重 sep 参数

我注意到,在 beamercolorbox 中,枚举环境不尊重 sep 参数(即完全忽略该参数)。这是一个最小的例子:

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

在此处输入图片描述

这是一个错误吗?还是这是预期的行为?无论如何,我该如何解决这个问题,即在彩色框内放置一个枚举,该枚举与框边框的间距与普通文本相同?

在此先感谢您的帮助!

答案1

新的尝试

  • 我的第一次尝试直接修补列表环境。
  • 这次尝试beamercolorbox通过更新列表环境使用的线宽来修补。请注意,将传递给选项beamercolorbox的值添加到和,但线宽不会更新。sep\leftskip\rightskip
% 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

beamerOP 使用的 v3.36变体

% 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

第一次尝试

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

在此处输入图片描述

更新至第一次尝试

这进一步的例子也包含针对itemize和环境的类似补丁。description

  • 由于\itemized的定义方式,我们需要\xpatchcmdxpatch包中进行修补。因此我将其全部替换\patchcmd\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}

在此处输入图片描述 在此处输入图片描述

相关内容