可以\framesubtitle
不使用\frametitle
in吗Beamer
?因为我想使用\frametitle
forsections
和\framesubtitle
for subsections
。
答案1
两种方法。
第一种方法定义了一个魔法词,叫做please hide this title
。只要标题正好是这个字符串,它就会被隐藏。
这个frametitle
模板定义只是 149-169 行原始模板定义的简单复制beamerouterthemedefault.sty
,只是生成标题的那一行被包裹在\ifx
.
\documentclass{beamer}
\usetheme{Madrid}
\begin{document}
\makeatletter
\def\stringpleasehidethistitle{{please hide this title\ifnum\beamer@autobreakcount>0\relax{}\space\usebeamertemplate*{frametitle continuation}\fi}}
\defbeamertemplate*{frametitle}{only sub}[1][left]
{
\ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
\@tempdima=\textwidth%
\advance\@tempdima by\beamer@leftmargin%
\advance\@tempdima by\beamer@rightmargin%
\begin{beamercolorbox}[sep=0.3cm,#1,wd=\the\@tempdima]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\if@tempswa\else\csname beamer@fte#1\endcsname\fi%
\ifx\insertframetitle\stringpleasehidethistitle% check if magic word presents
\else% check if magic word presents
\strut\insertframetitle\strut\par% check if magic word presents
\fi% check if magic word presents
{%
\ifx\insertframesubtitle\@empty%
\else%
{\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
\fi
}%
\vskip-1ex%
\if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
\end{beamercolorbox}%
}
\frame{{please hide this title}{only subtitle}}
\frame{{I want title}{title appears!}}
\frame{{please hide this title}{only subtitle again!}}
\frame{{I want title the second time}{title appears again!}}
\end{document}
第二种方法定义了一个替代frametitle
模板,但讽刺的是,它不显示任何框架标题。此定义只是 149-169 行原始定义的副本beamerouterthemedefault.sty
,只是生成标题的行被注释掉了。
\documentclass{beamer}
\usetheme{Madrid}
\begin{document}
\makeatletter
\defbeamertemplate*{frametitle}{only sub}[1][left]
{
\ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
\@tempdima=\textwidth%
\advance\@tempdima by\beamer@leftmargin%
\advance\@tempdima by\beamer@rightmargin%
\begin{beamercolorbox}[sep=0.3cm,#1,wd=\the\@tempdima]{frametitle}
\usebeamerfont{frametitle}%
\vbox{}\vskip-1ex%
\if@tempswa\else\csname beamer@fte#1\endcsname\fi%
%\strut\insertframetitle\strut\par% <-- This line is commented out
{%
\ifx\insertframesubtitle\@empty%
\else%
{\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\strut\par}%
\fi
}%
\vskip-1ex%
\if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
\end{beamercolorbox}%
}
\frame{{this title will be ignored}{only subtitle}}
\setbeamertemplate{frametitle}[default]
\frame{{switch back to the default}{title appears!}}
\setbeamertemplate{frametitle}[only sub]
\frame{{this title will be ignored again}{only subtitle again!}}
\setbeamertemplate{frametitle}[default]
\frame{{switch back to the default again}{title appears again!}}
\end{document}
结果和以前基本一样。