3

I'm trying to make a nice two column table of contents in beamer. There are a lot of questions about it, but I can't see that anyone really answers my problem.

Using the multicol environment, splitting the ToC is easy. However, the ToC is internally badly aligned, even thought the number of entries are even. I've added the code

\makeatletter
\patchcmd{\beamer@sectionintoc}
  {\vfill}
  {\vskip1.5em}
  {}
  {}
\makeatother

to add some more space, which also emphasises the bad alignment.

The question Beamer: Vertical alignment of multi-column ToC addresses the problem, but the solution is manual (providing which sections of the ToC that should be printed in which column). I believe it probably should be some way to fill the space needed in the first column such that the top of the two columns are balanced, but I have no idea how. Any ideas?

enter image description here

MWE:

\documentclass[xcolor=dvipsnames]{beamer}

\usepackage[utf8]{inputenc}
\usepackage{multicol,etoolbox}

\usetheme{Boadilla}
\usecolortheme[named=OliveGreen]{structure}
\usefonttheme[stillsansseriflarge]{serif}

\AtBeginSection[]
{
  \begin{frame}{Innhold}{\hfill}
  \begin{columns}
    \column{.1\textwidth}
    \column{.8\textwidth}
   \begin{multicols}{2}
      \centering
      \tableofcontents[currentsection, sectionstyle=show/shaded,
  %subsectionstyle=show/show/hide
  ]
   \end{multicols}
    \column{.1\textwidth}
\end{columns}
  \end{frame}
}

\makeatletter
\patchcmd{\beamer@sectionintoc}
  {\vfill}
  {\vskip1.5em}
  {}
  {}
\makeatother

\begin{document}

\begin{frame}
  {Innhold}{}
  \begin{columns}
    \column{.1\textwidth}
    \column{.8\textwidth}
      \begin{multicols}{2}
        \tableofcontents
      \end{multicols}
    \column{.1\textwidth}
  \end{columns}
\end{frame}

\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}

\end{document}
Holene
  • 6,920

1 Answers1

1

In beamerbasetoc.sty, there is the definition of \beamer@tableofcontents

\def\beamer@tableofcontents[#1]{%
  \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}%
  \vspace*{-.5em}{\makeatletter%
    \pause[0]%
    \@input{\jobname.toc}%
    \vfill}%
  }

Somehow the \vspace*{-.5em} at the beginning pushes down the TOC. So just remove it.


I know it is kind of surprising. Just try it and you will see the result.

Roughly speaking, multicols makes the first line of every column at least 1em tall, that is, it is of height 1em or higher. Therefore when you say \vspace*{-.5em}, the negative space itself becomes the first line. So you may image that the first line has height 1em and depth -.5em. It is indeed a positive space, and hence pushed the contents down.

P.S. Technically, \vspaces, the verticals spaces, are different from horizontal boxes and do not have heights and depths, they are spaces already.


MWE

\documentclass[xcolor=dvipsnames]{beamer}

\usepackage[utf8]{inputenc}
\usepackage{multicol,etoolbox}

\usetheme{Boadilla}
\usecolortheme[named=OliveGreen]{structure}
\usefonttheme[stillsansseriflarge]{serif}

\AtBeginSection[]
{
  \begin{frame}{Innhold}{\hfill}
  \begin{columns}
    \column{.1\textwidth}
    \column{.8\textwidth}
   \begin{multicols}{2}
      \centering
      \tableofcontents[currentsection, sectionstyle=show/shaded,
  %subsectionstyle=show/show/hide
  ]
   \end{multicols}
    \column{.1\textwidth}
\end{columns}
  \end{frame}
}

\makeatletter
\def\beamer@tableofcontents[#1]{%
  \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}%
  %\vspace*{-.5em}
  {\makeatletter%
    \pause[0]%
    \@input{\jobname.toc}%
    \vfill}%
  }
\makeatother

\begin{document}

\begin{frame}
  {Innhold}{}
  \begin{columns}
    \column{.1\textwidth}
    \column{.8\textwidth}
      \begin{multicols}{2}
        \tableofcontents
      \end{multicols}
    \column{.1\textwidth}
  \end{columns}
\end{frame}

\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}
\section{This is a section}
\begin{frame}
  {}
  Some content
\end{frame}

\end{document}
Symbol 1
  • 36,855