18

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.

16

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

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
  • 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 Apr 11 '11 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. – Gonzalo Medina Jun 1 '12 at 20:40
  • Wow, very professional! A question: How can I add the section-number here (in the last code-block)? – cis Oct 7 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.