更改投影仪中块的默认宽度

更改投影仪中块的默认宽度

我使用自定义 Beamer 主题进行演示。我想在演示中使用块 ( \begin{block}…\end{block})。这些块渲染得略微太宽,不适合我的主题。有没有办法设置块的默认宽度,例如.9\textwidth

答案1

如果您不需要具有可自定义宽度的新块环境,而只是想更改原始块环境的宽度,请在序言中添加以下内容:

\addtobeamertemplate{block begin}{%
  \setlength{\textwidth}{0.9\textwidth}%
}{}

\addtobeamertemplate{block alerted begin}{%
  \setlength{\textwidth}{0.9\textwidth}%
}{}

\addtobeamertemplate{block example begin}{%
  \setlength{\textwidth}{0.9\textwidth}%
}{}

答案2

您可以定义自己的块环境,并使用可选参数作为其宽度并提供默认值,例如.9\textwidth

以下是一个例子:

\documentclass{beamer}
\usetheme{Warsaw}
\usepackage[english]{babel}

\newenvironment<>{varblock}[2][.9\textwidth]{%
  \setlength{\textwidth}{#1}
  \begin{actionenv}#3%
    \def\insertblocktitle{#2}%
    \par%
    \usebeamertemplate{block begin}}
  {\par%
    \usebeamertemplate{block end}%
  \end{actionenv}}

\begin{document}

\begin{frame}
\begin{block}{Standard}
  Normal block
\end{block}
\begin{varblock}[4cm]{New block}
  Variable width, here 4cm
\end{varblock}
\begin{varblock}{New block}
  If no width was given, .9\textbackslash textwidth will be used
\end{varblock}
\end{frame}

\end{document}

变量块示例

我发布了这个例子这里在2008。

答案3

使用 Stefan Kottwitz 的代码并做了微小的修改,我将其放在了我的序言中。

% Variable width block
\newenvironment<>{varblock}[2][0.9\textwidth]{%
    \setlength{\textwidth}{#1}%
    \setlength{\linewidth}{\textwidth}% required to itemize respect the width of block
  \begin{actionenv}#3%
    \def\insertblocktitle{#2}%
    \par%
    \usebeamertemplate{block begin}}
  {\par%
  \usebeamertemplate{block end}%
  \end{actionenv}}

% Variable width example block
\newenvironment<>{varexampleblock}[2][0.9\textwidth]{%
    \setlength{\textwidth}{#1}%
    \setlength{\linewidth}{\textwidth}%
  \begin{actionenv}#3%
    \def\insertblocktitle{#2}%
    \par%
    \setbeamercolor{local structure}{parent=example text}%
    \usebeamertemplate{block example begin}}
  {\par%
  \usebeamertemplate{block example end}%
    \end{actionenv}}

% Variable width alert block
\newenvironment<>{varalertblock}[2][0.9\textwidth]{%
    \setlength{\textwidth}{#1}%
    \setlength{\linewidth}{\textwidth}%
  \begin{actionenv}#3%
    \def\insertblocktitle{#2}%
    \par%
    \setbeamercolor{local structure}{parent=alerted text}%
    \usebeamertemplate{block alerted begin}}
  {\par%
  \usebeamertemplate{block alerted end}%
    \end{actionenv}}

相关内容