Beamer:可以混合使用不同的主题吗?

Beamer:可以混合使用不同的主题吗?

我一般用Warsaw主题,如果文档包含多个章节,标题行会包含多行,相比之下我更喜欢infolines外层主题设计的标题。

因此,我想混合使用Warsawinfolines主题。更准确地说,我需要使用Warsaw来自的标题infolines

我在主题文件中找到了标题的定义beamerouterthemeinfolines.sty

\defbeamertemplate*{headline}{infolines theme}
{%
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{section in head/foot}%
    \usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{subsection in head/foot}%
    \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsubsectionhead
  \end{beamercolorbox}}%
  \vskip0pt%
}

我尝试使用\setbeamertemplate{headline}[infolines theme]after \usetheme{Warsaw}。但是它不起作用。

但将定义主体复制到设置模板效果很好headline

\documentclass{beamer}
\usetheme{Warsaw}
%\setbeamertemplate{headline}[infolines theme] % this doesn't work
\setbeamertemplate{headline}
{%
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{section in head/foot}%
    \usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{subsection in head/foot}%
    \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsubsectionhead
  \end{beamercolorbox}}%
  \vskip0pt%
}
\begin{document}
\section{section~1}
\subsection{subsection~1.1}
\begin{frame}
  \begin{example}
    page~1
  \end{example}
\end{frame}
\subsection{subsection~1.2}
\frame{page~2}
\section{section~2}
\subsection{subsection~2.2}
\frame{page~3}
\subsection{subsection~2.2}
\frame{page~4}
\end{document} 

结果如图所示。

在此处输入图片描述

我认为将代码复制到序言中不是一个好选择。 有没有什么方法可以\setbeamertemplate{headline}[infolines theme]让标题看起来像这样infolines

答案1

您可以使用以下解决方法之一https://github.com/josephwright/beamer/issues/388#issuecomment-296338235

\documentclass{beamer}
\usetheme{Warsaw}
%\setbeamertemplate{headline}[infolines theme] % this doesn't work

\makeatletter
\let\beamer@original@defbeamertemplate\beamer@defbeamertemplate
\def\beamer@defbeamertemplate{\beamer@sbtfalse\@ifstar{\beamer@sbtoo}{\beamer@sbtoo}}
\useoutertheme{infolines}
\setbeamertemplate{headline}[infolines theme] 
% This \set must be done manually, 
% since generally theme names have nothing to do with file names
\let\beamer@defbeamertemplate\beamer@original@defbeamertemplate
\makeatother

\begin{document}
\section{section~1}
\subsection{subsection~1.1}
\begin{frame}
  \begin{example}
    page~1
  \end{example}
\end{frame}
\subsection{subsection~1.2}
\frame{page~2}
\section{section~2}
\subsection{subsection~2.2}
\frame{page~3}
\subsection{subsection~2.2}
\frame{page~4}
\end{document} 

在此处输入图片描述

相关内容