[Tex/LaTex] In beamer, how can you use \tableofcontents[hidesubsections] and still render correctly the TOC

beamertable of contents

Using: pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013)

When using the \tableofcontents in beamer, using the theme Berkeley, with the option [hidesubsections], [hideothersubsections] and the options to hide subsections, it renders the TOC wrongly. It introduces too much space to separate the section names.

The aim is to have a slide before each beginning of a section, with the ToC highlighting the current section and showing its subsections.

Given the following Minimal not Working Example(MnWE):

    \documentclass[]{beamer}

    \usetheme{Berkeley}

    \begin{document}

    \AtBeginSection[]{
    \frame{
    \tableofcontents[currentsection,hideothersubsections]
    }
    }

    \begin{frame}
    \tableofcontents[hidesubsections]
    \end{frame}

    \begin{frame}
    \tableofcontents[currenthideallsubsections]
    \end{frame}

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

    \section{section 1}
    \subsection{subsection1}
    \begin{frame}
    subsection1
    \end{frame}
    \subsection{subsection2}
    \begin{frame}
    subsection1
    \end{frame}

    \section{section 2}
    \subsection{subsection1}
    \begin{frame}
    subsection1
    \end{frame}
    \subsection{subsection2}
    \begin{frame}
    subsection1
    \end{frame}

    \section{section 3}hidesubsections
    \begin{frame}
    subsection1
    \end{frame}
    \section{section 4}
    \begin{frame}
    subsection1
    \end{frame}
    \section{section 5}
    \begin{frame}
    subsection1
    \end{frame}
    \section{section 6}
    \begin{frame}
    subsection1
    \end{frame}
    \section{section 7}
    \begin{frame}
    subsection1
    \end{frame}
    \section{section 8}
    \begin{frame}
    subsection1
    \end{frame}
    \end{document}

It will show the following images for the first, and third slide. The second is the same as the first:

The TOC with hidesubsections option and displayed wrongly, too many space to separate section names:
The TOC with hidesubsections option and too many space to separate section names

The TOC without hidesubsections option, displayed correctly:
The TOC without hidesubsections option, displayed correctly.

Best Answer

This is the updated answer:

The internal command \beamer@sectionintoc (defined in the file beamerbasetoc.sty) controls how the section entries will be typeset in the ToC; it issues a \vskip1.5em that adds vertical spacing between section entries. With the help of the etoolbox package you can easily patch the command to add less vertical spacing.

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{etoolbox}

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

\title[Short Title]{My very long title that doesn't fix into the footer}
\author{Me}
\date{\today}
\beamertemplatenavigationsymbolsempty
\setbeamertemplate{footline}[frame number]
\usetheme{CambridgeUS}

\AtBeginSection[]
{
\begin{frame}
\frametitle{Outline}
\tableofcontents[currentsection, hideothersubsections]
\end{frame}
}

\begin{document}

\maketitle
\clearpage

\begin{frame}
\frametitle{Outline}
\tableofcontents[hideothersubsections]
\end{frame}


\section{Intro}
\begin{frame}
\frametitle{Welcome}
...
\end{frame}

\section{Topic 1}
\begin{frame}
\frametitle{Topic 1}
...
\end{frame}

\section{Topic 2}
\begin{frame}
\frametitle{Topic 2}
...
\end{frame}

\subsection{Red}
\begin{frame}
\frametitle{Red}
...
\end{frame}

\subsection{Green}
\begin{frame}
\frametitle{Green}
...
\end{frame}

\subsection{Blue}
\begin{frame}
\frametitle{Blue}
...
\end{frame}

\section{Topic 3}
\begin{frame}
\frametitle{Topic 3}
...
\end{frame}

\section{Topic 4}
\begin{frame}
\frametitle{Topic 4}
...
\end{frame}

\section{Topic 5}
\begin{frame}
\frametitle{Topic 5}
...
\end{frame}

\section{Topic 6}
\begin{frame}
\frametitle{Topic 6}
...
\end{frame}

\section{Topic 7}
\begin{frame}
\frametitle{Topic 7}
...
\end{frame}

\section{Topic 8}
\begin{frame}
\frametitle{Topic 8}
...
\end{frame}

\section{The end}
\begin{frame}
\frametitle{The end}
End of file :-)
\end{frame}

\end{document}

I think this should probably be the right answer.