我试图让最后一节的标题显示为 frametitle 仅有的在每个代码之后的第一帧上\section{...}
。
现在,我使用此代码手动执行此操作:
\newcommand{\TS}[0]{
\mode<beamer>{
\frametitle{\thesection \insertsection}
}}
\section{title of the last section}
然后我在该代码之后的第一帧上手动输入了以下内容:
\section{title of the last section}
\begin{frame}
\TS
content of the frame with the last section in frametitle.
\end{frame}
\begin{frame}
This is the second frame without a title.
\end{frame}
所以我想让这个自动完成(并且如果存在的话也把子部分作为框架副标题,并且只有当前部分已经在前一帧显示时才把子部分作为框架标题....我希望我足够精确)。
我读了这个主题尝试使用部分代码对其进行定制,但没有任何成功。
答案1
您需要找到与框架相关的钩子。下面我使用了仅在之后的第一帧\beamer@checkframetitle
插入的钩子:\insertsectiontitle
\section
\documentclass{beamer}
\makeatletter
\newcommand<>{\insertsectiontitle}{\frametitle{\thesection~\insertsection}}
\let\oldbeamer@checkframetitle\beamer@checkframetitle% Store the \frametitle checking mechanism
\renewcommand<>{\section}{%
\gdef\beamer@checkframetitle{% Update \frametitle checking to ...
\insertsectiontitle% ...insert the section title and...
\global\let\beamer@checkframetitle\oldbeamer@checkframetitle% ...revert to it's old definition
}% Regular \section stuff follows
\alt#1{\@ifnextchar[\beamer@section\beamer@@section}
{\beamer@secgobble}}
\makeatother
\begin{document}
\section{title of the last section}
\begin{frame}
content of the frame with the last section in frametitle.
\end{frame}
\begin{frame}
This is the second frame without a title.
\end{frame}
\end{document}
\subsection
对上述内容进行更新,\framesubtitle
在第一张幻灯片中插入后 \section
,之后\frametitle
:
\documentclass{beamer}
\makeatletter
\newcommand<>{\insertsectiontitle}{\frametitle{\thesection~\insertsection}}
\newcommand<>{\insertsubsectiontitle}{\frametitle{\thesubsection~\insertsubsection}}
\newcommand<>{\insertsubsectionsubtitle}{\framesubtitle{\thesubsection~\insertsubsection}}
\let\oldbeamer@checkframetitle\beamer@checkframetitle% Store the \frametitle checking mechanism
\renewcommand<>{\section}{%
\gdef\beamer@checkframetitle{% Update \frametitle checking to ...
\insertsectiontitle% ...insert the section title and...
\ifx\relax\insertsubsection\relax
\global\let\beamer@checkframetitle\oldbeamer@checkframetitle% ...revert to it's old definition - no subsection
\else
\insertsubsectionsubtitle% ...insert the subsection title and...
\global\let\beamer@checkframetitle\insertsubsectiontitle% ...always insert subsection
\fi
}% Regular \section stuff follows
\alt#1{\@ifnextchar[\beamer@section\beamer@@section}
{\beamer@secgobble}}
\makeatother
\begin{document}
\section{First section}
\subsection{First subsection}
\begin{frame}
Frame 1
\end{frame}
\begin{frame}
Frame 2
\end{frame}
\subsection{Second subsection}
\begin{frame}
Frame 3
\end{frame}
\begin{frame}
Frame 4
\end{frame}
\section{Second section}
\subsection{First subsection}
\begin{frame}
Frame 5
\end{frame}
\begin{frame}
Frame 6
\end{frame}
\end{document}