Beamer - включить подраздел в \frametitle, но только если подраздел существует, т.е. нет оглавления, опорных кадров и т.д.

Beamer - включить подраздел в \frametitle, но только если подраздел существует, т.е. нет оглавления, опорных кадров и т.д.

Продолжая отэтот ответ от samcarter_is_at_topanswers.xyzв отношении вопроса section title in \frametitle beamerя использовал предоставленный ответ:

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

в моем основном beamerдокументе. Я изменил его так, чтобы вместо \insertsectionнего было , \insertsubsectionтак как мои подразделы более релевантны. Однако использование этого предсказуемо влияет на все мои frame' независимо от того, \insertsubsectionявляется ли пустым (например, для страниц TOC). Мой основной документ в настоящее время выглядит так (я использовал \insertsection\ - \insertframetitleвместо этого, обратите внимание на пробелы вокруг дефиса):

введите описание изображения здесь

Как я могу проверить или включить только \patchcmdэффект 's, когда присутствует подраздел (или с помощью любого метода/раздела, который работает)? Я также включаю TOC для каждого раздела, используя:

\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}

Выход МВЭ:

введите описание изображения здесь

В идеале я хочу, чтобы заголовок подраздела находился в соответствующих рамках, но только если подраздел существует, а не в оглавлении/справочных/вводных слайдах и т. д. Если это невозможно, то я вернусь к отсутствию подразделов в , \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}

Связанный контент