2

I want to test if a given page is a section page in beamer.

The idea is to draw a progress bar, and 'mark' the positions of the next section. However, for that I need to know if a given page is a section page, and if it is then do something.

This is how I draw the progressbar:

\setbeamertemplate{background}{%
    \progressbar@tmpcounta=\insertframenumber
    \progressbar@tmpcountb=\inserttotalframenumber
    \progressbar@tmpdim=\progressbar@progresswidth
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb

    \begin{tikzpicture}
        \useasboundingbox (0,0) rectangle (\the\paperwidth, \the\paperheight);
        \fill[color=FuwaWhite] (0,0) rectangle (12.8cm, 9.6cm);

        \ifnum\thepage=1\relax\else
            \draw[fill=FuwaGreen,draw=none] (0cm, 0cm) rectangle (\progressbar@tmpdim,0.05cm);
            \node[anchor=south] at(6.4cm, 0.1cm) {\color{FuwaAnthrazit}\tiny\insertdate};
            \node[anchor=south east] at(12.8cm, 0.1cm) {\color{FuwaAnthrazit}\tiny\insertframenumber/%
                \inserttotalframenumber};
        \fi
        \foreach \x in {1,...,\inserttotalframenumber} {%
            \progressbar@tmpdim=\progressbar@progresswidth
            \divide\progressbar@tmpdim by \totvalue{section}
            \draw[fill=FuwaGreen!50!FuwaBlack,draw=none] (\x*\progressbar@tmpdim, 0) rectangle (\x*\progressbar@tmpdim+0.05cm, 0.05cm);
        }
   \end{tikzpicture}
}

However they are evenly spaced, I want them to be spaced to be like the sections. So I would instead iterate over each page and check if that page is a section page (i.e., what beamer considers a section page) and then draw something.

Neikos
  • 133

1 Answers1

3

I might not be able to check if its a section page, but I can check if a page is the first page of a section. Is it save to assume that every first page of your sections is a section page?

\documentclass{beamer}

\usepackage{etoolbox}
\makeatletter
\newcount\beamer@sectionstartframe
\beamer@sectionstartframe=1
\apptocmd{\beamer@section}{\addtocontents{nav}{\protect\headcommand{%
            \protect\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}{}{}
\apptocmd{\beamer@section}{\beamer@sectionstartframe=\c@framenumber\advance\beamer@sectionstartframe by1\relax}{}{}
\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}}{}{}
\def\beamer@startframeofsection{1}
\def\beamer@endframeofsection{1}
\def\beamer@sectionframes#1#2{%
    \ifnum\c@framenumber<#1%
    \else%
    \ifnum\c@framenumber>#2%
    \else%
    \gdef\beamer@startframeofsection{#1}%
    \gdef\beamer@endframeofsection{#2}%
    \fi%
    \fi%
}
\newcommand\insertsectionstartframe{\beamer@startframeofsection}
\newcommand\insertsectionendframe{\beamer@endframeofsection}
\makeatother

\setbeamertemplate{headline}{%
    \ifnum\insertsectionstartframe=\insertframenumber%
        \Huge I'm section!
    \fi%
    }

\begin{document}

    \section{The First}

    \begin{frame}
        First slide
    \end{frame}

    \begin{frame}
        Second slide
    \end{frame}

    \begin{frame}
        Third slide
    \end{frame}

    \begin{frame}
        Fourth slide
    \end{frame}

    \section{The Second}

    \begin{frame}
        First slide
    \end{frame}

    \begin{frame}
        Second slide
    \end{frame}

    \begin{frame}
        Third slide
    \end{frame}

\end{document}