4

For some applications, e.g. Links in mindmap as table of contents in beamer the default beamer table of contents is not flexible enough

How to manually recreate a basic beamer toc as starting point for crazy things?

1 Answers1

3

The following code produces a rudimentary toc with much less functionality than the origional beamer toc, but it really just meant as a starting point for more complicate things that would not be possible with the default toc.

\documentclass{beamer}

\usepackage{tikz}

\setbeamercolor{subsection in toc}{fg=black}

% total number of sections %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{totcount}
\newcounter{totalsection}
\regtotcounter{totalsection}
\AtBeginDocument{%
  \pretocmd{\section}{\refstepcounter{totalsection}}{}{}%
}%

% number of subsections per section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xcntperchap}
\RegisterCounters{section}{subsection}
\newcounter{totalsubsection}
\setcounter{totalsubsection}{0}

% creating automatic label %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% based on https://tex.stackexchange.com/a/386557/36296
\AtBeginSection[]{\label{sec:\thesection}}
\AtBeginSubsection[]{\label{subsec:\thesection:\thesubsection}}
\newcounter{currentsub}
\newcounter{totsection}

% custom toc
\newcommand{\mytoc}{%
    \begingroup%
        \usebeamerfont{section in toc}%
      \usebeamercolor[fg]{section in toc}%
    \setcounter{totsection}{\number\totvalue{totalsection}}%
    \foreach \i in {1,...,\thetotsection}{%
        \hyperlink{sec:\thesection}{\nameref{sec:\i}}%
            \setcounter{currentsub}{\ObtainTrackedValueExp[\i]{section}{subsection}}%
            \par%
            \begingroup
                \usebeamerfont{subsection in toc}%
                \usebeamercolor[fg]{subsection in toc}%
                \ifnum\thecurrentsub>0%
                    \foreach \j in {1,...,\thecurrentsub}{%
                        \hspace{1cm}\hyperlink{subsec:\i:\j}{\nameref{subsec:\i:\j}}%
                        \par%
                    }%
                \fi%
            \endgroup
            \vfill
        }% loop over i
    \endgroup
}

\title{Some Title}

\begin{document}

\begin{frame}
    \mytoc
\end{frame}

\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}

\section{Section 2}
\frame{}

\section{Section 3}
\subsection{Subsection 3a}
\frame{}
\subsection{Subsection 3b}
\frame{}
\subsection{Subsection 3c}
\frame{}

\end{document}

enter image description here