5

I want to automatically insert the section title with its number in each beamer frame (or in just some of them). How can we achieve this?

  • 1
    \insertsection gives you the title of the current section, \thesection the number – user36296 Nov 20 '15 at 19:41
  • thank you very much! samcarter But how to get this done automatically (if possible ) in each frame ? – Hafid Boukhoulda Nov 20 '15 at 20:34
  • I did it by reading the documentation. Just look through the themes and pick one you like. – cfr Nov 21 '15 at 3:36
  • @BoukhouldaHafid depends on where you want to put the information. It would be helpfull if you would provide a minimal working example – user36296 Nov 21 '15 at 10:44
  • \section{section one} \begin{frame} 1. section one .... .... \end{frame} \section{section two} \begin{frame} 2. section two .... ..... \end{frame} I want this to be done automatically for all the frames – Hafid Boukhoulda Nov 21 '15 at 13:31
4
\documentclass{beamer}

\setbeamertemplate{frametitle}{\thesection.~\insertsection~\insertframetitle}

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

\begin{document}

\section{section one} 
\begin{frame}
blub
\end{frame} 

\section{section two} 
\begin{frame}
blub
\end{frame}

\end{document}

enter image description here

2

In the Latex beamer document class, the frame title (and subtitle) for a frame are defined in beamerouterthemedefault.

To override the definition, you can copy the definition into your Latex file and enclose it with \makeatletter and \makeatother.

For example, to add the section number before the title, change the following line and add \thesection.~\insertsection:~ before \insertframetitle:

\strut\thesection.~\insertsection:~\insertframetitle\strut\par%

Full Example:

\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usetheme{default}

\makeatletter
\defbeamertemplate*{frametitle}{customized}[1][left]
{%
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{beamercolorbox}[sep=0.3cm,#1,wd=\the\@tempdima]{frametitle}
    \usebeamerfont{frametitle}%
    \vbox{}\vskip-1ex%
    \if@tempswa\else\csname beamer@fte#1\endcsname\fi%
    % The following line was modified to insert
    % section number (\thesection)
    % and section title (\insertsection).
    \strut\thesection.~\insertsection:~\insertframetitle\strut\par%
    {%
      \ifx\insertframesubtitle\@empty%
      \else%
      {\usebeamerfont{framesubtitle}\usebeamercolor[fg]%
         {framesubtitle}\insertframesubtitle\strut\par}%
      \fi
    }%
    \vskip-1ex%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
  \end{beamercolorbox}%
}
\makeatother

\begin{document}

\section{Section Title}

\begin{frame}{Frame Title}
Some text.
\end{frame}


\end{document}

Result:

Latex beamer frame with section number and title

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.