2

For stylistic reasons (I have everything in blocks), I'd like to have my TOC in a block too, but without having to typset it manually for all sections.

I was surprised that the standard tikz TOC produces garbage when inserted into a block.

Therefore, I tried several methods of building an approximation to the behaviour I'd like (basically like itemize/enumerate), but while I managed to hack something reasonably similar together for the sections, I was unable to get the subsections right at all.

First, I thought it only boils down to knowing exactly which skips to use and how to get them (took me ages to figure the \global stuff out; thanks to https://tex.stackexchange.com/a/43005/42225 and https://tex.stackexchange.com/a/119738/42225), but now I'm finding other strange behaviour (indendation changes for things that are defined exactly the same; can't change font size or color in subsection, etc.), which is why I turn to you, dear TeX.SX.

In the MWE below is a "reference solution" that I'd like to achieve with the standard TOC-functionality. Ideally, they should match exactly, but a few pt's here or there won't hurt anyone. ;-)

\documentclass[10pt]{beamer}

\usepackage[english]{babel}
\usepackage{enumerate}
\usepackage{xparse}

\usetheme{Darmstadt}

\NewDocumentCommand{\mytoc}{O{}}{
\begin{frame}{Test}
\begin{block}{Table of Contents}
    \vskip 6pt % shouldn't be hardcoded...
    \tableofcontents[#1]
\end{block}
\end{frame}
}

%\AtBeginSection{%
%   \mytoc[currentsection]
%}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{frame}{Reference}
\begin{block}{Table of Contents}
\begin{enumerate}[1.]
    \item Motivation
    \item Construction
    \item The Method
    \item Improvements
    \item Applications
    \begin{enumerate}[\theenumi.1.]
        \item One
        \item Two
        \item Three
    \end{enumerate}
\end{enumerate}
\end{block}
\end{frame}

\begin{frame}{Na\"ive version}
\begin{block}{Doesn't work}
\tableofcontents
\end{block}
\end{frame}

\setbeamertemplate{section in toc}{\item[\inserttocsectionnumber.]\inserttocsection}
\begin{frame}{Trying to use itemize}
\begin{block}{Doesn't work}
\begin{itemize}
\tableofcontents
\end{itemize}
\end{block}
\end{frame}

\newlength{\itemsepEnumi}
\newlength{\labelsepEnumi}
\newlength{\parsepEnumi}
\newlength{\topsepEnumi}
\newlength{\partopsepEnumi}
\newlength{\leftmarginEnumi}

\newlength{\itemsepEnumii}
\newlength{\labelsepEnumii}
\newlength{\parsepEnumii}
\newlength{\topsepEnumii}
\newlength{\partopsepEnumii}
\newlength{\leftmarginEnumii}

\newlength{\partopsepEnumz} % z=zero

\begin{frame}{Data Collection}
\begin{block}{Relevant Values} % see tex.stackexchange.com/a/94949/42225
\begin{enumerate}[1.]
  \item \texttt{itemsep}:    \the\itemsep    \global\itemsepEnumi   =\itemsep
                                             \global\labelsepEnumi  =\labelsep
  \item \texttt{parsep}:     \the\parsep     \global\parsepEnumi    =\parsep
  \item \texttt{topsep}:     \the\topsep     \global\topsepEnumi    =\topsep
  \item \texttt{partopsep}:  \the\partopsep  \global\partopsepEnumi =\partopsep
  \item \texttt{leftmargin}: \the\leftmargin \global\leftmarginEnumi=\leftmargin
  \begin{enumerate}[\theenumi.1.]
    \item \texttt{itemsep}:    \the\itemsep    \global\itemsepEnumii   =\itemsep
                                               \global\labelsepEnumii  =\labelsep
                                               \global\parsepEnumii    =\parsep
                                               \global\topsepEnumii    =\topsep
    \item \texttt{partopsep}:  \the\partopsep  \global\partopsepEnumii =\partopsep
    \item \texttt{leftmargin}: \the\leftmargin \global\leftmarginEnumii=\leftmargin
  \end{enumerate}
\end{enumerate}
\global\partopsepEnumz=\partopsep
\end{block}
\end{frame}

\begin{frame}{Data Collection -- Successful}
\begin{block}{Relevant Values}
\begin{enumerate}[1.]
  \item \texttt{itemsep}:    \the\itemsepEnumi
%  \item \texttt{labelsep}:   \the\labelsepEnumi
  \item \texttt{parsep}:     \the\parsepEnumi
  \item \texttt{topsep}:     \the\topsepEnumi
  \item \texttt{partopsep}:  \the\partopsepEnumi
  \item \texttt{leftmargin}: \the\leftmarginEnumi
  \begin{enumerate}[\theenumi.1.]
    \item \texttt{itemsep}:    \the\itemsepEnumii
%    \item \texttt{labelsep}:   \the\labelsepEnumii
%    \item \texttt{parsep}:     \the\parsepEnumii
%    \item \texttt{topsep}:     \the\topsepEnumii
    \item \texttt{partopsep}:  \the\partopsepEnumii
    \item \texttt{leftmargin}: \the\leftmarginEnumii
  \end{enumerate}
\end{enumerate}
%\texttt{partopsep}:  \the\partopsepEnumz
\end{block}
\end{frame}

\setlength{\leftmarginEnumii}{33.3334pt} % how to add skips?

\setbeamertemplate{section in toc}{\leavevmode\leftskip=\leftmarginEnumi%
    \llap{\inserttocsectionnumber.\hspace{\labelsepEnumi}} % why is this automatically blue?
    {\color{black}\smash[b]{\inserttocsection}}\par\vskip\itemsepEnumi}
\setbeamertemplate{section in toc shaded}{\leavevmode\leftskip=\leftmarginEnumi%
    {\color{gray}\llap{\inserttocsectionnumber.\hspace{\labelsepEnumi}}\smash[b]{\inserttocsection}} \par\vskip\itemsepEnumi\vskip\parsepEnumi}
\setbeamertemplate{subsection in toc}{\leavevmode\leftskip=\leftmarginEnumii%
    \llap{%\usetemplate{itemize 2 item} % can't set color/fontsize?!
    \inserttocsectionnumber.\inserttocsubsectionnumber.\hspace{\labelsepEnumii}}
    {\color{black}\smash[b]{\inserttocsubsection}} \par\vskip\itemsepEnumii \vskip\parsepEnumii}
\setbeamertemplate{subsection in toc shaded}{\leavevmode\leftskip=\leftmarginEnumii%
    {\color{gray}\llap{\inserttocsectionnumber.\inserttocsubsectionnumber.\hspace{\labelsepEnumii}}\smash[b]{\inserttocsubsection}} \par\vskip\itemsepEnumii\vskip\parsepEnumii}

\begin{frame}{Trying to Use Skips}
\begin{block}{Doesn't work}
  \vskip\partopsepEnumz % is this the right set/combination of skips?
  \vskip\partopsepEnumi
  \vskip\topsepEnumi
  \tableofcontents
\end{block}
\end{frame}

\begin{frame}{Reference}
\begin{block}{Table of Contents}
\begin{enumerate}[1.]
    \item Motivation
    \item Construction
    \item The Method
    \item Improvements
    \item Applications
    \begin{enumerate}[\theenumi.1.]
        \item One
        \item Two
        \item Three
    \end{enumerate}
\end{enumerate}
\end{block}
\end{frame}

\begin{frame}{Indentation changes from \texttt{section} to \texttt{section shaded}?!}
\begin{block}{Table of Contents}
    \vskip 6pt
    \tableofcontents
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Motivation}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Construction}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The Method}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Improvements}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Applications}
\subsection{One}
\mytoc[currentsection,currentsubsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Two}
\mytoc[currentsection,currentsubsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Three}
\mytoc[currentsection,currentsubsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}

\end{document}
1

This is not a perfect match but perhaps it will be close enough to at least give you a basis for further tweaking. Basically, this inserts the block environment into beamer's definition of \tableofcontents and defines a new style my toc for sections/subsections in toc. Because it does not use enumerate, the spacing is not quite the same but this is something you can play with. Also, I have forced the colouring to match an enumeration - I'm not sure if you want this or not but you can easily undo it.

\documentclass[10pt]{beamer}

\usetheme{Darmstadt}

\makeatletter
\def\tableofcontents{\@ifnextchar[{\beamer@tableofcontents}{\beamer@tableofcontents[]}}
\def\beamer@tableofcontents[#1]{%
  \begin{block}{\contentsname}
      \def\beamer@toc@cs{show}%
      \def\beamer@toc@os{show}%
      \def\beamer@toc@css{show}%
      \def\beamer@toc@oss{show}%
      \def\beamer@toc@ooss{show}%
      \def\beamer@toc@csss{show}%
      \def\beamer@toc@osss{show}%
      \def\beamer@toc@oosss{show}%
      \def\beamer@toc@ooosss{show}%
      \beamer@showpartnumber=\c@part%
      \beamer@pausesectionsfalse%
      \beamer@pausesubsectionsfalse%
      \def\beamer@tocsections{<*>}%
      \setkeys{beamertoc}{firstsection=1}%
      \setkeys{beamertoc}{#1}%
      {\makeatletter%
        \pause[0]%
        \@input{\jobname.toc}}%
  \end{block}
  }
\makeatother

\defbeamertemplate{section in toc}{my toc}{%
  \leavevmode\inserttocsectionnumber. {\color{normal text.fg}\inserttocsection}}

\defbeamertemplate{subsection in toc}{my toc}{%
  \leavevmode\leftskip=2.5em{\color{structure.fg}\inserttocsectionnumber.\inserttocsubsectionnumber.} \inserttocsubsection\par}

\setbeamertemplate{sections/subsections in toc}[my toc]

\begin{document}

  \renewcommand*\contentsname{Table of Contents}

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


  \begin{frame}{Reference}
    \begin{block}{Table of Contents}
      \begin{enumerate}[1.]
        \item Motivation
        \item Construction
        \item The Method
        \item Improvements
        \item Applications
        \begin{enumerate}[\theenumi.1.]
          \item One
          \item Two
          \item Three
        \end{enumerate}
      \end{enumerate}
    \end{block}
  \end{frame}

  \section{Motivation}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

  \section{Construction}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

  \section{The Method}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

  \section{Improvements}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

  \section{Applications}
  \subsection{One}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

  \subsection{Two}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

  \subsection{Three}

  \begin{frame}{Something}
    \begin{block}{Something}
      Something
    \end{block}
  \end{frame}

\end{document}

Note that this code does not cover subsubsections, although you could extend it to those if you wished.

faked enumeration for toc in block in beamer

  • Thanks for your answer! Sorry for this very delayed response, I was away on a conference. Ultimately, I decided to keep my work-around (there were still some weird spacing issues); however, elements from your answer (using \def... instead of \set..., resp. defining an own style my toc instead of overwriting existing styles) were very useful to achieve the desired appearance. So thanks again for that! – Axel Oct 27 '14 at 10:41

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.