我想在演示文稿的标题中显示当前部分的名称(即类似于精简版的infolines
外部主题)。以下 MWE几乎做我想要的:
\documentclass{beamer}
\AtBeginSection[]{{
\setbeamertemplate{headline}{} % temporarily redefine headline to be empty
\frame{\tableofcontents[currentsection]}
}}
\setbeamercolor{mysection}{fg=bg,bg=fg}
\title{The Title}
\author{A.~U.~Thor}
\begin{document}
\maketitle % We don't want a headline
\begin{frame}{Slide 0}Zero\end{frame} % Still don't want a headline
\setbeamertemplate{headline}{\leavevmode%
\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex]{mysection}%
\hbox to .5\paperwidth{\hspace{.5em}\insertsectionhead\hfil}
\end{beamercolorbox}%
\vskip0pt}
\section{Section A}
\begin{frame}{Slide 1}One\end{frame}
\begin{frame}{Slide 2}Two\end{frame}
\section{Section B}
\begin{frame}{Slide 3}Three\end{frame}
\end{document}
具体来说,上述文件有以下内容期望特性:
- 直到章节开始后才显示标题
- 不显示宣布新部分开始的插页幻灯片上的标题
它有两个问题:
\setbeamertemplate{headline}...
它通过在文档中间简单地设置模板()来避免在前几张幻灯片中显示标题。我想在序言中做这种定义(这样我就可以将其重构为自己的文件中的真正外部主题)。- 它会生成过满的垂直盒子(
Overfull \vbox (9.66663pt too high) has occurred while \output is active []
)。
我该如何解决这些问题?例如,也许可以通过引入一些条件逻辑来检测部分编号是否为零来解决 (1)。
答案1
这个怎么样?
- 将您的定制移至
\setbeamertemplate{headline}{\leavevmode ...}
序言中。 - 创建一个从一开始
nobeamerheadline
就发出的新环境。\setbeamertemplate{headline}{}
上述解决方案的额外功能:它还允许您在其他地方隐藏标题,例如“谢谢/问题?”框架。以下是我的方法:
\documentclass{beamer}
\AtBeginSection[]{%
\begingroup
\setbeamertemplate{headline}{}% temporarily redefine headline to be empty
\frame{\tableofcontents[currentsection]}
\endgroup
}
\setbeamertemplate{headline}{\leavevmode
\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex]{mysection}%
\hbox to .5\paperwidth{\hspace{.5em}\insertsectionhead\hfil}
\end{beamercolorbox}%
\vskip0pt}
\setbeamercolor{mysection}{fg=bg,bg=fg}
\newenvironment{nobeamerheadline}{%
\begingroup
\setbeamertemplate{headline}{}
}{%
\endgroup
}
\title{The Title}
\author{A.~U.~Thor}
\begin{document}
\begin{nobeamerheadline}
\maketitle % We don't want a headline
\begin{frame}{Slide 0}Zero\end{frame} % Still don't want a headline
\end{nobeamerheadline}
\section{Section A}
\begin{frame}{Slide 1}One\end{frame}
\begin{frame}{Slide 2}Two\end{frame}
\section{Section B}
\begin{frame}{Slide 3}Three\end{frame}
\end{document}
顺便说一句,我没有收到任何Overfull \vbox
警告信息。
答案2
另一种方法是从技术上在所有框架上显示标题,但在部分开始之前使其不可见:
\documentclass{beamer}
\AtBeginSection[]{{
\setbeamertemplate{headline}{}
\frame{\tableofcontents[currentsection]}
}}
\title{The Title}
\author{A.~U.~Thor}
\setbeamertemplate{headline}{%
\ifnum\thesection>0
\setbeamercolor{mysection}{bg=fg}
\else
\setbeamercolor{mysection}{bg=bg}
\fi
\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex]{mysection}%
\hbox to .5\paperwidth{\hspace{.5em}\insertsectionhead\hfil}
\end{beamercolorbox}%
}
\begin{document}
\maketitle % We don't want a headline
\begin{frame}{Slide 0}Zero\end{frame} % Still don't want a headline
\section{Section A}
\begin{frame}{Slide 1}One\end{frame}
\begin{frame}{Slide 2}Two\end{frame}
\section{Section B}
\begin{frame}{Slide 3}Three\end{frame}
\end{document}
最终我认为最简单的方法是在适当的地方使用普通框架:
\documentclass{beamer}
\AtBeginSection[]{
\begin{frame}[plain]
\tableofcontents[currentsection]
\end{frame}
}
\title{The Title}
\author{A.~U.~Thor}
\setbeamercolor{mysection}{bg=fg,fg=bg}
\setbeamertemplate{headline}{%
\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex]{mysection}%
\hbox to .5\paperwidth{\hspace{.5em}\insertsectionhead\hfil}
\end{beamercolorbox}%
}
\begin{document}
\begin{frame}[plain]
\titlepage
\end{frame}
\begin{frame}[plain]
\frametitle{Slide 0}
Zero
\end{frame}
\section{Section A}
\begin{frame}{Slide 1}One\end{frame}
\begin{frame}{Slide 2}Two\end{frame}
\section{Section B}
\begin{frame}{Slide 3}Three\end{frame}
\end{document}