[Tex/LaTex] Table of contents in multicol alignment problem

multicoltable of contentsvertical alignment

In my report I'd like to have a short table of contents, thus I printed it with multicol in two columns to safe space. But the alignment on the top is like in the picture.enter image description here

I'd more prefer it if the first row of the second column is aligned to the first entry of my toc of the first column. All in all Section 3 should move to the left column below Section 2 and Section 4 shall stay in one line with Section 1.

I found some solutions, but they were somehow very manual where you have to write yourself which section appears in which column. Here, so far, everything happens automatically 🙂

My code so far:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
%%%%%% additional packages
\usepackage{multicol}
\usepackage{etoolbox}
%%%%%%

\setcounter{tocdepth}{1} %set depth of printed table of contets.

\makeatletter
\patchcmd{\l@section}
  {\hfil}
  {\leaders\hbox{\normalfont$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep     mu$}\hfill}
  {}{}
\makeatother %print dots in sections in toc.

\begin{document}


\begin{multicols}{2}
\tableofcontents
\end{multicols}


\section{Introduction}%%%%%%%%%%Introduction
\subsection{bla}
\subsubsection{blabla}

\section{Approach}%%%%%%%%%%Approach
\subsection{bla}
\subsubsection{blabla}

\section{Experimental results}%%%%%%%%%%Experimental results
\subsection{bla}
\subsubsection{blabla}

\section{Discussion}%%%%%%%%%%Discussion
\subsection{bla}
\subsubsection{blabla}

\section{Summary}%%%%%%%%%%Summary
\subsection{bla}
\subsubsection{blabla}


\end{document}

Thank you very much,
SemtexB

Best Answer

enter image description here

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
%%%%%% additional packages
\usepackage{multicol,etoolbox}
%%%%%%

\setcounter{tocdepth}{2} %set depth of printed table of contets.

\makeatletter


\patchcmd{\l@section}
  {\hfil}
  {\leaders\hbox{\normalfont$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep     mu$}\hfill}
  {}{}

\renewcommand\tableofcontents{%
    \begin{multicols}{2}[\section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}]%
    \@starttoc{toc}%
    \end{multicols}%
    }

\makeatother %print dots in sections in toc.

\begin{document}


\tableofcontents


\section{zz}
aa
\section{bbbb}
\subsection{xgxgxgxg}
aaa
\subsection{xgxgxgxg}
aaa
\subsection{xgxgxgxg}
aaa
\subsection{xgxgxgxg}


\end{document}
Related Question