Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Thank you! Those pretocmd and patchcmd macros are stunning. –  Archibald Jul 29 '11 at 10:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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