4

I am working on my slides in beamer and I would like to include some dots in the header indicating the current section (left) and subsection (right). The names of the sections/subsections should not be included.

Here is a MWE:

\documentclass{beamer}

\makeatletter
\setbeamertemplate{headline}
{%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=0.5\paperwidth,ht=2.25ex,dp=1ex,left]{section in head/foot}
            section dots
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=0.5\paperwidth,ht=2.25ex,dp=1ex,right]{section in head/foot}
            subsection dots (of current section)
        \end{beamercolorbox}}%
}
\makeatother

\begin{document}    
    \section{Section1}
    \begin{frame}
        \frametitle{Frame11}
    \end{frame}

    \subsection{Subsection1}
    \begin{frame}
        \frametitle{Frame12}
    \end{frame}

    \subsection{Subsection2}
    \begin{frame}
        \frametitle{Frame13}
    \end{frame}


    \section{Section2}
    \begin{frame}
        \frametitle{Frame21}
    \end{frame}

    \subsection{Subsection1}
    \begin{frame}
        \frametitle{Frame22}
    \end{frame}

    \subsection{Subsection2}
    \begin{frame}
        \frametitle{Motivation}
    \end{frame}

    \subsection{Subsection3}
    \begin{frame}
        \frametitle{Frame23}
    \end{frame}
\end{document}

For this specific number of frames, I want two dots in the top-left corner indicating the sections and two or three dots in the top-right corner indicating the subsections of section 1 and section 2, respectfully. Obviously, I want a general solution that is not specific to this example.

Is this done easily in my current setup or is something entirely different needed?

2
  • How should the dots look like? Highlight just the current section, highlight all sections including the current section? Commented Jun 7, 2016 at 10:53
  • @samcarter: Highlighting only the current section/subsection (by a full dot) is what I am thinking right now, but customizability is highly valued. Non-current sections/subsections should be "empty dots" (circles).
    – Thomas
    Commented Jun 7, 2016 at 10:58

2 Answers 2

2

There are probably much better ways to do this, but instead of messing with beamer navigation I wanted to try something new and play with the xcntperchap package.

\documentclass{beamer}
\usepackage{tikz}

\usepackage{totcount}
\regtotcounter{section}

\usepackage{xcntperchap}
\RegisterCounters{section}{subsection}

\newcounter{totalsubsection}
\setcounter{totalsubsection}{0}
\usepackage{etoolbox}

\preto\frame{\ifnum\thesection>0\setcounter{totalsubsection}{\ObtainTrackedValueExp[\thesection]{section}{subsection}}\fi}

\setbeamertemplate{headline}{%
\hbox{%
\begin{beamercolorbox}[wd=.48\paperwidth,ht=2.25ex,dp=1ex]{section in head/foot}%
\hfill%
\ifnum\totvalue{section}>0%
\ifnum\thesection>0%
\foreach\x in {1,...,\totvalue{section}}{%
\ifnum\x=\thesection%
\usebeamertemplate{mini frame}~%
\else%
\usebeamertemplate{mini frame in other section}~%
\fi%
}%
\fi%
\fi%
\end{beamercolorbox}%
\qquad%
\begin{beamercolorbox}[wd=.48\paperwidth,ht=2.25ex,dp=1ex]{subsection in head/foot}%
\ifnum\thetotalsubsection>0%
\foreach\x in {1,...,\thetotalsubsection}{%
\ifnum\x=\thesubsection%
\usebeamertemplate{mini frame}~%
\else%
\usebeamertemplate{mini frame in other subsection}~%
\fi%
}%
\fi%
\end{beamercolorbox}%
}}

\title{title}
\author{author}

\begin{document}

    \begin{frame}
        \titlepage
    \end{frame}


\section{Section1}

\frame{}

\subsection{Subsection1}
\begin{frame}
\frametitle{Frame11}
\end{frame}

\subsection{Subsection2}
\begin{frame}
\frametitle{Frame12}
\end{frame}

\section{Section2}
\begin{frame}
\frametitle{Frame2}
\end{frame}

\subsection{Subsection1}
\begin{frame}
\frametitle{Frame21}
\end{frame}

\subsection{Subsection2}
\begin{frame}
\frametitle{Frame22}
\end{frame}

\subsection{Subsection3}
\begin{frame}
\frametitle{Frame23}
\end{frame}

\section{Section3}
\begin{frame}
\frametitle{Frame3}
\end{frame}

\end{document}

enter image description here

11
  • (+1) for promoting xcntperchap ;-) (And the solution itself, of course too!)
    – user31729
    Commented Jun 7, 2016 at 20:00
  • I get the error: "LaTeX error: "kernel/command-already-defined" Control sequence __xassoccnt_container: already defined. For immediate help type H <return>. ...iner_clist \xassoccnt_counter_container:n" while the "\RegisterCounters{section}{subsection}"-line is marked in red. What seems to be the problem?
    – Thomas
    Commented Jun 9, 2016 at 9:42
  • @Thomas mmm, sounds like some problem with xcntperchap. What version are you using? I am on texlive 2016 and xcntperchap version 0.2. Commented Jun 9, 2016 at 16:48
  • I am on TeX Live 2015 and xcntperchap 0.2.
    – Thomas
    Commented Jun 10, 2016 at 8:00
  • @Thomas Mmmm, I tried also with TeX Live 2015 and I do not get this error. However I fixed the problem that threw errors on the first run, see the edit. Commented Jun 10, 2016 at 8:49
2

I am just answering to show the flexibility of the accepted solution. All credit goes to samcarter. By changing minor stuff in the if/else and moving content from the header to the footer, I obtained the following nMWE outcome:

First four slides

Slides 5-8

The nMWE:

\documentclass{beamer}

\beamertemplatenavigationsymbolsempty
\usetheme{rochester}
\usecolortheme{beaver}

\usepackage{tikz}

\usepackage{totcount}
\regtotcounter{section}

\usepackage{xcntperchap}
\RegisterCounters{section}{subsection}

\newcounter{totalsubsection}
\setcounter{totalsubsection}{0}
\usepackage{etoolbox}

\preto\frame{\ifnum\thesection>0\setcounter{totalsubsection}{\ObtainTrackedValueExp[\thesection]{section}{subsection}}\fi}

\setbeamertemplate{footline}{%
    \hbox{%
        \begin{beamercolorbox}[wd=0.2\paperwidth,ht=2.25ex,dp=1ex,left,leftskip=1ex]{subsection in head/foot}%
            \ifnum\totvalue{section}>0%
            \foreach\x in {1,...,\totvalue{section}}{%
                \ifnum\numexpr\x-1<\thesection%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other section}~%
                \fi%
            }%
            \fi%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=0.6\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}
            \usebeamerfont{title in head/foot} \inserttitle
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=0.2\paperwidth,ht=2.25ex,dp=1ex,right,rightskip=1ex]{subsection in head/foot}%
            \ifnum\thetotalsubsection>0%
            \foreach\x in {1,...,\thetotalsubsection}{%
                \ifnum\x>\numexpr\thetotalsubsection-\thesubsection%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other subsection}~%
                \fi%
            }%
            \fi%
        \end{beamercolorbox}%
    }}


\title{Super fancy long title which will fit in the footer}
\author{The Champion}
\date{\today}


\begin{document}

    \begin{frame}
        \thispagestyle{empty}
        \maketitle
    \end{frame}


    \begin{frame}
        \thispagestyle{empty}
        \frametitle{Outline}
        \tableofcontents
    \end{frame}


    \section{The first section}
    \subsection{The first subsection}
    \begin{frame}
        \frametitle{The first section}
        \framesubtitle{The first subsection}
    \end{frame}

    \subsection{The second subsection}
    \begin{frame}
        \frametitle{The first section}
        \framesubtitle{The second subsection}
    \end{frame}

    \subsection{The third subsection}
    \begin{frame}
        \frametitle{The first section}
        \framesubtitle{The third subsection}
    \end{frame}


    \section{The second section}
    \subsection{The first subsection}
    \begin{frame}
        \frametitle{The second section}
        \framesubtitle{The first subsection}
    \end{frame}

    \subsection{The second subsection}
    \begin{frame}
        \frametitle{The second section}
        \framesubtitle{The second subsection}
    \end{frame}


    \section{The third section}
    \subsection{The first subsection}
    \begin{frame}
        \frametitle{The third section}
        \framesubtitle{The first subsection}
    \end{frame}

\end{document}

You must log in to answer this question.

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