Beamer - 在 \frametitle 中包含小節,但僅當小節存在時,即不存在 TOC、參考幀等

Beamer - 在 \frametitle 中包含小節,但僅當小節存在時,即不存在 TOC、參考幀等

繼從samcarter_is_at_topanswers.xyz 的回答關於這個問題section title in \frametitle beamer,我使用了提供的答案:

\makeatletter
\patchcmd\beamer@@tmpl@frametitle{\insertframetitle}{\insertsection-\insertframetitle}{}{}
\makeatother

在我的主要beamer文檔中。我已經修改了它,這樣\insertsection\insertsubsection的小節就更相關了。但是,使用此功能可以預見會影響 my 的所有內容,frame無論是否\insertsubsection為空白(例如 TOC 頁面)。我的主文件目前看起來像這樣(我使用的\insertsection\ - \insertframetitle是,請注意連字符周圍的空格):

在此輸入影像描述

\patchcmd當存在小節(或通過任何有效的方法/部門)時,如何測試或僅包含的效果?我還使用以下內容在每個部分中包含一個目錄:

\AtBeginSection[]
{
 \ifnum \value{framenumber}>1
  \begin{frame}<beamer>
   \frametitle{Outline}
   \tableofcontents[currentsection]
  \end{frame}
 \else
 \fi
}

和參考文獻,最後可能還有術語表。我看到的一個可能的解決方案是重新修補\beamer@@tmpl@frametitle我希望或不希望標題中出現該小節的幻燈片之前和之後重新修補命令,但也許有一種更好的方法超出了我的知識範圍,可以在其他人到達,因此出現這個問題。我嘗試這樣做是為了避免問一個多餘的問題,但它失敗了,如下:

在此輸入影像描述

使用:

\newcommand\showSubsec{
\makeatletter
\patchcmd\beamer@@tmpl@frametitle{\insertframetitle}{\insertsubsection\ - \insertframetitle}{}{}
\makeatother
}

\newcommand\hideSubsec{
\makeatletter
\patchcmd\beamer@@tmpl@frametitle{\insertsubsection\ - \insertframetitle}{\insertframetitle}{}{}
\makeatother
}

微量元素:

\documentclass{beamer}

\usepackage{xpatch}
\makeatletter
\patchcmd\beamer@@tmpl@frametitle{\insertframetitle}{\insertsubsection\ - \insertframetitle}{}{}
\makeatother

% For TOC at each section
\AtBeginSection[]
{
 \ifnum \value{framenumber}>1
  \begin{frame}<beamer>
   \frametitle{Outline}
   \tableofcontents[currentsection]
  \end{frame}
 \else
 \fi
}

\begin{document}

\begin{frame}
\frametitle{Outline}
\tableofcontents
\end{frame}

\begin{frame}
\frametitle{Introduction}
Introduction
\end{frame}

\section{First section}
\subsection{First subsection}
\begin{frame}
    \frametitle{First slide Title}
    Text
\end{frame}

\subsection{Second subsection}
\begin{frame}
    \frametitle{Second slide Title}
    \small
    Text
\end{frame}

\section{Conclusions and Future Work}
\subsection{Conclusions}
\begin{frame}
    \frametitle{Conclusions}
    \centering
    Text
\end{frame}

\subsection{Future Work}
\begin{frame}
    \frametitle{Future Work}
    \centering
    Text
\end{frame}

\section*{Back matter}
\subsection*{References}
\begin{frame}
\frametitle{References}
References
\end{frame}

\end{document}

MWE 輸出:

在此輸入影像描述

理想情況下,我希望在相關框架中包含小節標題,但前提是該小節存在,而不是在目錄/參考/介紹幻燈片等。小節,\frametitle但如果可能的話那就太好了請。

答案1

例如,您可以測試分段計數器是否 > 0:

\documentclass{beamer}

\usepackage{xpatch}
\makeatletter
\patchcmd\beamer@@tmpl@frametitle{\insertframetitle}{%
\ifnum\thesubsection>0
  \insertsubsection\ - 
\fi
\insertframetitle
}{}{}
\makeatother

% For TOC at each section
\AtBeginSection[]
{
 \ifnum \value{framenumber}>1
  \begin{frame}<beamer>
   \frametitle{Outline}
   \tableofcontents[currentsection]
  \end{frame}
 \else
 \fi
}

\begin{document}

\begin{frame}
\frametitle{Outline}
\tableofcontents
\end{frame}

\begin{frame}
\frametitle{Introduction}
Introduction
\end{frame}

\section{First section}
\subsection{First subsection}
\begin{frame}
    \frametitle{First slide Title}
    Text
\end{frame}

\subsection{Second subsection}
\begin{frame}
    \frametitle{Second slide Title}
    \small
    Text
\end{frame}

\section{Conclusions and Future Work}
\subsection{Conclusions}
\begin{frame}
    \frametitle{Conclusions}
    \centering
    Text
\end{frame}

\subsection{Future Work}
\begin{frame}
    \frametitle{Future Work}
    \centering
    Text
\end{frame}

\section*{Back matter}
\subsection*{References}
\begin{frame}
\frametitle{References}
References
\end{frame}

\end{document}

相關內容