1

Section 10.5 of the LaTeX Beamer manual specifies the different options for generating a table of contents. One of them is:

firstsection=⟨section number⟩ specifies which section should be numbered as section “1.” This is useful if you have a first section (like an overview section) that should not receive a number. Section numbers are not shown by default. To show them, you must install a different table of contents templates.

There is a similar option lastsection. In my case, however, I need an unnumbered section in the middle of my sections, not the start or the end. The following is a photoshopped mock-up (a tock-up, if you will) of what I mean:

Tockup

It's acceptable if you redefine \section* in your answer, as I want all \sections and \section*s to be shown in the TOC and \section*'s only default purpose is precisely not to be shown in TOC. Hence, the above mock-up could result from the following MWE:

\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}

\begin{document}
    \begin{frame}
        \tableofcontents
    \end{frame}
    
    \section*{Intro}
    \section{First section}
    \section{Second section}
    \section*{Nope}
    \section{Third section}
    \section*{Outro}
    
    \begin{frame}   
    \end{frame}
\end{document}

1 Answer 1

1

The following code introduces a command \nonumsec that creates a \section* and adds an entry to the .toc file with the final argument set to 0. This causes Beamer (somehow) to not print the number. The code for adding an entry is copied from the Beamer source, particularly beamerbasesection.sty.

There may be side effects so test carefully.

MWE:

\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}

\makeatletter
\newcommand{\nonumsec}[1]{%
\section*{#1}%
\addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#1}{\the\c@page}{\the\c@part}%
        {0}}%
}
\makeatother

\begin{document}
    \begin{frame}
        \tableofcontents
    \end{frame}
    
    \nonumsec{Intro}
    \section{First section}
    \section{Second section}
    \nonumsec{Nope}
    \section{Third section}
    \nonumsec{Outro}
    
    \begin{frame}   
    \end{frame}
\end{document}

Resulting TOC file:

\beamer@sectionintoc {1}{Intro}{2}{0}{0}
\beamer@sectionintoc {2}{First section}{2}{0}{1}
\beamer@sectionintoc {3}{Second section}{2}{0}{2}
\beamer@sectionintoc {4}{Nope}{2}{0}{0}
\beamer@sectionintoc {5}{Third section}{2}{0}{3}
\beamer@sectionintoc {6}{Outro}{2}{0}{0}

PDF output is the same as in the tock-up.

You must log in to answer this question.

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