1

I want to create the following template for the \tableofcontents in beamer. enter image description here

I am able to generate the code for the list of sections and subsections with the following MWE

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\setbeamerfont{section in toc}{family*=qag, size=\large,series=\bfseries}
\setbeamerfont{subsection in toc}{size=\normalsize,series=\bfseries}
\setbeamertemplate{subsection in toc}{%
    \begin{tikzpicture}[outer sep=0pt, inner sep=0pt,line width=0pt]
        \path[use as bounding box] (0,0) rectangle (\textwidth,0);
        \node[anchor=base east] at (.7\textwidth,0) { \inserttocsubsection};
    \end{tikzpicture}
}
\setbeamertemplate{section in toc}{%
    \begin{tikzpicture}[outer sep=0pt, inner sep=0pt,line width=0pt]
        \path[use as bounding box] (0,0) rectangle (\textwidth,0);
        \node[anchor=base east] at (.7\textwidth,0) { \inserttocsection};
        \node[anchor=base west] at (.7\textwidth+4ex+2.2ex,0){\inserttocsectionnumber};
    \end{tikzpicture}
}
\begin{document}
\begin{frame}
\tableofcontents
\end{frame}

\section{First Section} \section{Second Section} \subsection{A subsection} \begin{frame}{Some frame} \end{frame} \end{document}

However, I do not find a smart way to insert the vertical line. If I use the background template, I can do it but the positioning is not easy (and strongly depends on the aspectratio and the margins). The same happens with overlay in tikzpicture. I tried to find a way to enclose the section in toc templates within a tikzpicture and define each template as a collection of nodes, but it seems \tableofcontets is more complex than I thought. For example, using \patchcmd is not a good choice.

1 Answers1

0

You could label the nodes and then draw your line from the first to the last section:

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\setbeamerfont{section in toc}{family*=qag, size=\large,series=\bfseries}
\setbeamerfont{subsection in toc}{size=\normalsize,series=\bfseries}
\setbeamertemplate{subsection in toc}{%
    \begin{tikzpicture}[outer sep=0pt, inner sep=0pt,line width=0pt]
        \path[use as bounding box] (0,0) rectangle (\textwidth,0);
        \node[anchor=base east] at (.7\textwidth,0) { \inserttocsubsection};
    \end{tikzpicture}
}
\setbeamertemplate{section in toc}{%
    \begin{tikzpicture}[outer sep=0pt, inner sep=0pt,line width=0pt,remember picture]
        \path[use as bounding box] (0,0) rectangle (\textwidth,0);
        \node[anchor=base east] (toc-\inserttocsectionnumber) at (.7\textwidth,0) { \inserttocsection};
        \node[anchor=base west] at (.7\textwidth+4ex+2.2ex,0){\inserttocsectionnumber};
    \end{tikzpicture}
}

\makeatletter \apptocmd{\tableofcontents}{% \begin{tikzpicture}[remember picture,overlay] \draw[red,line width=0.1cm] ([xshift=4.1ex,yshift=2ex]toc-1.north east) -- ([xshift=4.1ex,yshift=-2ex]toc-\the\beamer@sectionmax.south east); \end{tikzpicture}% }{}{} \makeatother

\begin{document} \begin{frame} \tableofcontents \end{frame}

\section{First Section} \begin{frame} \frametitle{Some frame} \end{frame} \section{Second Section} \subsection{A subsection} \begin{frame} \frametitle{Some frame} \end{frame} \section{Third Section} \begin{frame} \frametitle{Some frame} \end{frame} \end{document}

enter image description here

If your last section is going to include subsections, you could label them as well and use https://topanswers.xyz/tex?q=1987#a2230 to figure out the last subsection number.