3

In a LaTeX article, \section* behaves like this:

\documentclass[12pt]{article} \begin{document}
\section*{Not numbered} \thesection % --> 0
\section{Numbered} \thesection % --> 1
\end{document}

However, with beamer the following happens:

\documentclass[12pt]{beamer} \begin{document}
\section*{Not numbered} \frame{\thesection}  % --> 1
\section{Numbered} \frame{\thesection} % --> 2
\end{document}

Why is this? Could I correct this behaviour?

Now, what I actually need is a command \secnr for beamer that will print nothing when in a starred section and the correct -viz. documentclass article- numbering in unstarred sections. So that would require:

  1. Fixing the numbering misbehavious in beamer
  2. An if to test "if current section is starred ..."

A solution to either (or both) of these problems would be very welcome.

1 Answer 1

2

beamer implements \section* in a different way. The actual section number is kept in the (TeX) counter \beamer@tocsectionnumber, which is not advanced when \section* is found.

A possible solution to your problems is

\usepackage{etoolbox}
\newif\ifstarred
\def\secnr{}
\makeatletter
\pretocmd\beamer@@ssection{\gdef\secnr{}\global\starredtrue}{}{}
\patchcmd\beamer@section{by 1\relax}
  {by 1\relax\xdef\secnr{\the\beamer@tocsectionnumber}\global\starredfalse}{}{}
\makeatother

This defines \secnr as you want: in a \section* it expands to nothing, while in a \section it expands to the section's number. The \ifstarred conditional is true after a \section* and false after a \section.

1
  • Thank you! Those pretocmd and patchcmd macros are stunning.
    – Archibald
    Jul 29, 2011 at 10:50

You must log in to answer this question.

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