2

I'm very new to StackExchange, let alone LaTeX. The issue here is temporarily adding a frame title to whichever frame comes right after a new subsection is defined. Following is a sample code with an empty ribbon left behind on the first slide.

\documentclass{beamer}
\usepackage{lipsum}
\usetheme{Frankfurt}
\AtBeginSubsection[]
{
\addtobeamertemplate{frametitle}{\let\insertframetitle\insertsubsectionhead}{}
}

\makeatletter
  \CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
  \renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother

\begin{document}
\section{Introduction}

\begin{frame}
\lipsum[2]
\end{frame} 

\subsection{XYZ}

\begin{frame}
\lipsum[2]
\end{frame}

\end{document}

Basically wanting a similar set-up to this but only for the first frame right after a new subsection starts, without any permanent impact to other frames/frame titles (like said empty ribbons on pages).

EDIT: Found this link which got 90 percent of the job done, but the subsection frame title disappears if overlay specifications (like \uncover) are present in the same frame, as well as displaces individual frame titles (that makes sense).

TLDR for edit: stays only on first slide after new subsection, not same frame.

\documentclass{beamer}
\usepackage{lipsum}
\usetheme{Frankfurt}

\makeatletter
\newcommand<>{\insertsubsectiontitle}{\frametitle{\insertsubsection}}
\let\oldbeamer@checkframetitle\beamer@checkframetitle% Store the \frametitle checking mechanism
\renewcommand<>{\subsection}{%
  \gdef\beamer@checkframetitle{% Update \frametitle checking to ...
    \insertsubsectiontitle% ...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@subsection\beamer@@subsection}
    {\beamer@secgobble}}
\makeatother

\begin{document}
\section{Introduction}

\begin{frame}
\lipsum[2]
\end{frame} 

\subsection{XYZ}

\begin{frame}
\lipsum[2]
\end{frame}

\end{document}
4
  • 2
    Welcome to TeX.SE! Can you please make your code snippet be compilable? Then we do not have to guess what you are doing ...
    – Mensch
    Apr 23, 2022 at 16:01
  • 2
    Welcome to TeX.SE! People here will more easy to help you if you will provide an example of complete small document, which reproduce your problem.
    – Zarko
    Apr 23, 2022 at 16:02
  • Changes have been made, thank you for reminding. Apr 24, 2022 at 10:06
  • 1
    Maybe a question of mine from the past would be helpful for you. Check the answer given in the comments.
    – tush
    Apr 24, 2022 at 14:01

1 Answer 1

1

If the frame following the subsection only has one overlay, you can use the following redefinition of the frametitle template.

(if your document starts with a subsection on frame one, remove \ifnum\thepage>1 ... fi from the code)

\documentclass{beamer}
\usepackage{lipsum}
\usetheme{Frankfurt}

\makeatletter
\setbeamertemplate{frametitle}{%
\ifnum\thepage>1
\ifnum\insertsubsectionstartpage=\thepage
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    \if@tempswa\else\csname beamer@fteleft\endcsname\fi%
    \strut\insertsubsectionhead\strut\par%
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
\fi\fi
\ifx\insertframetitle\@empty
\else
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,left,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    \if@tempswa\else\csname beamer@fteleft\endcsname\fi%
    \strut\insertframetitle\strut\par%
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\strut\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
\fi
}

\CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother

\begin{document}
\section{Introduction}

\begin{frame}
\lipsum[2]
\end{frame} 

\subsection{XYZ}

\begin{frame}
\lipsum[2]
\end{frame}

\begin{frame}
\frametitle{title}
\lipsum[2]
\end{frame}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .