21

Is there a way to automatically use the section name as the frame title and the subsection name as the frame subtitle?

I think this question is related, but when I tried to hack that solution to change the substitution from \insertsubsectionhead to \insertsectionhead as follows, my frame title simply disappeared:

\addtobeamertemplate{frametitle}{
   \let\insertframetitle\insertsectionhead}{}

(later)

\section{Introduction}

\begin{frame}
   \frametitle{}

. . . 

Does it matter where that template manipulation appears? I have it in my preamble right after I choose my theme.

Bottom line: I have no idea how these internals work, so worst case I'll just continue duplicating the sections and subsection names into the frame titles and subtitles. I like the idea of keeping that connection back to the outline in every frame.

2 Answers 2

18

To use section and subsection names in frame title in beamer, one can use \secname and \subsecname as shown below:

\section{About project}
\subsection{Easy stuff}
\begin{frame}{\secname : \subsecname}
    ...
\end{frame}
13

As the answer in the question you linked explains, it is not enough to add simply

\addtobeamertemplate{frametitle}{
   \let\insertframetitle\insertsectionhead}{}

this will work if you explicitly use a \frametitle{} command for each frame. The same answer explains how to avoid using the command explicitly by adding

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

So, in your case, you'll have to add the following lines to the preamble:

\addtobeamertemplate{frametitle}{
   \let\insertframetitle\insertsectionhead}{}
\addtobeamertemplate{frametitle}{
   \let\insertframesubtitle\insertsubsectionhead}{}


\makeatletter
  \CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
  \renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother
4
  • Thanks for the answer, Gonzalo. I think there must be something about the theme that I am using or something because I can't get it to work. I did try the empty \frametitle{} without the extra \makeatletter command before, so I guess I understood something about what was said there in the older answer, but it did not have the desired effect. I am using the Madrid theme, and I did try your solution with the default theme, but now the title bar is not even there. I have no idea how to troubleshoot this. If you have any suggestions I'll be glad to work with you. Thanks for your time.
    – Neil Best
    Commented Apr 11, 2011 at 23:54
  • @NeilBest for some reason, I only read you comment today; I apologize. If you are still interested in this issue, please edit your question by adding a complete but simple document showing the problem you mentioned. Commented Jun 1, 2012 at 20:40
  • Wow, very professional! A question: How can I add the section-number here (in the last code-block)?
    – cis
    Commented Oct 7, 2019 at 13:56
  • @GonzaloMedina I've used your answer to my presentation and it worked very well. However, I want the final frame not to include any title (now it includes the title of my final section). I used \begin{frame}[plain], but it doesn't change nothing. Is there a solution for this issue?
    – Emo
    Commented Jun 7, 2022 at 13:30

You must log in to answer this question.

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