我已經從 PowerPoint 移植了我大學在 Beamer 中的模板,並添加了一些程式碼來顯示標題中的部分(以及子部分,如果存在的話)。
headline
這是我為此目的放入模板中的程式碼片段:
\begin{beamercolorbox}[wd=0.6\paperwidth,ht=0.1\beamer@PoliMI@headheight]{section in head/foot}%
\usebeamerfont{section in head/foot}\par%
\vfill\strut\insertsectionhead%
\ifx\insertsubsection\empty\else%
~--~\insertsubsectionhead%
\fi%
\strut\par%
\end{beamercolorbox}\\%
但是,當從小節「退出」(發出\subsection*{}
)時,仍會列印節名稱後面的破折號。
如何測試小節名稱是否無效?
作為替代方案,我怎樣才能\insertsubsection
清空?
微量元素:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}\normalfont
\usepackage[T1]{fontenc}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{headline}{%
\begin{beamercolorbox}[wd=0.6\paperwidth,ht=0.016\paperwidth]{section in head/foot}%
\usebeamerfont{section in head/foot}%
\par\vfill\strut\insertsectionhead%
\ifx\insertsubsection\empty\else~--~\insertsubsectionhead%
\fi\strut\par%
\end{beamercolorbox}%
}
\begin{document}
\section{aaa}
\begin{frame}~\end{frame}
\subsection{bbb}
\begin{frame}~\end{frame}
\subsection*{}
\begin{frame}~\end{frame}
\end{document}
在第三幀中,只有「aaa」必須出現,而不是「aaa -」。
更新:如果 subsection 尚未定義,\insertsubsection
則為空,而如果\subsection*{}
發出 a ,巨集將在 中展開\expandafter \hyperlink \subsectionlink
,子節要么為空(\insertsubsectionhead
展開為\hyperlink {Navigation\the \c@page }{}
),要么不為空(在第二幀中\insertsubsectionhead
展開為)。\hyperlink {Navigation\the \c@page }{bbb}
答案1
我已將程式碼片段替換為
\ifx\insertsubsection\empty\else%
\ifdefempty{\subsecname}{\relax}{%
~--~\insertsubsectionhead%
}%
\fi
它有效!
不幸的是需要etoolbox
加載包...
編輯:
\setbox0=\hbox{\subsecname\unskip}\ifdim\wd0=0pt\else%
~--~\insertsubsectionhead%
\fi%
也有效且不需要etoolbox
。
我不知道這是否是“更乾淨”的解決方案。
答案2
我無法發表評論,但我對 @Astrinus 的第二個解決方案有疑問,但仍然想分享它。
\subsecname
建立新節時預設不會刪除。替換它\insertsubsectionhead
可以為我解決這個問題。
\setbox0=\hbox{\insertsubsectionhead\unskip}\ifdim\wd0=0pt\else%
- \insertsubsectionhead%
\fi%
答案3
我在透過以下方式識別小節結尾時遇到問題:
\ifx\insertsubsection\empty
將 SubSection 限制在大括號中使其起作用:
{
\subsection{SubSection Title}
<subsection frames>
}
<other frames>
該 SubSection 內部和外部的框架之間的條件正確不同