4

In my pretty long presentation, I am attempting to write a beamer theme with sections, subsections and frames navigational bullets as in picture below mini sections, mini subsections and mini frames navigational bullets

I find out that there is no build-in theme meets my need. So how can we achieve this?

3

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.

Remarks:

  • requires two compilations
  • does not provide clickable links

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\usepackage{totcount}
\regtotcounter{section}

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

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

\preto\frame{\setcounter{totalsubsection}{\ObtainTrackedValueExp[\value{section}]{section}{subsection}}}

\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

\usetikzlibrary{calc}

\def\inserttotalsectionframenumber{%
    \pgfmathparse{(\insertsectionendframe-\insertsectionstartframe+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\def\insertsectionframenumber{%
    \pgfmathparse{(\insertframenumber-\insertsectionstartframe+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\newcounter{sectionframenumber}
\newcounter{totalsectionframenumber}

\setbeamertemplate{headline}{%
    \vskip1em%
    \hbox{%  
        \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex]{section in head/foot}%
            \centering%
            \insertsection\par%
            \vskip0.2em%
            \foreach\x in {1,...,\totvalue{section}}{%
                \ifnum\x=\value{section}%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other section}~%
                \fi%
            }%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex]{subsection in head/foot}%
            \ifnum\value{totalsubsection}>0%
            \centering%
            \insertsubsection\par%
            \vskip0.2em%
            \foreach\x in {1,...,\value{totalsubsection}}{%
                \ifnum\x=\value{subsection}%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other subsection}~%
                \fi%
            }%
            \fi%
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.3\paperwidth,ht=2.25ex,dp=1ex]{section in head/foot}%
            \centering%
            \ifx\insertframetitle\empty\else%
                \insertframetitle\par%
            \fi%
            \vskip0.2em%
            \setcounter{sectionframenumber}{1}
            \addtocounter{sectionframenumber}{\insertframenumber}
            \addtocounter{sectionframenumber}{-\insertsectionstartframe}
            \setcounter{totalsectionframenumber}{1}
            \addtocounter{totalsectionframenumber}{\insertsectionendframe}
            \addtocounter{totalsectionframenumber}{-\insertsectionstartframe}
            \foreach\x in {1,...,\value{totalsectionframenumber}}{%
                \ifnum\x=\value{sectionframenumber}%
                \usebeamertemplate{mini frame}~%
                \else%
                \usebeamertemplate{mini frame in other subsection}~%
                \fi%
            }%
        \end{beamercolorbox}%       
    }}

    \def\insertframetitle{}

    \begin{document}    
        \section{Section1}
        \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}

        \frame{}

    \end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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