# Make ToC in the center and left aligned in beamer

Using the following code I could put the ToC lines in the center in beamer:

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


But how to make these ToC lines left aligned and still in the center?

-
You can only put the \tableofcontents inside a minipage-environment which can be centered via \centering. – Marco Daniel Dec 10 '11 at 17:12
The question tex.stackexchange.com/questions/47702/… contains a fairly simple solution (manually calculated though) – naught101 May 2 '12 at 0:27

A small calculation could advance the margins sufficiently to obtain the centered & left-aligned \tableofcontents display.

\documentclass{beamer}% http://ctan.org/pkg/beamer
\newsavebox{\longestsec}% Box to save longest sectional heading
\begin{document}

\begin{frame}
\begin{lrbox}{\longestsec}Last section in the presentation\end{lrbox}% Capture longest title
\tableofcontents
\end{frame}

\section{First section}
​\begin{frame}
\frametitle{First slide}
This is a slide.
\end{frame}

\section{Last section in the presentation}% Longest sectional title
\begin{frame}
\frametitle{Another slide}
This is another slide
\end{frame}
\end{document}


​The reason for this round-about way is because beamer collapses the spacing when putting \tableofcontents within a minipage or varwidth (from the varwidth package).

-
Great. But is it possible to automatically find out the longest sectional title? – Z.H. Dec 16 '11 at 12:07