[Tex/LaTex] Removing space before Section in Table of Contents when using Article

spacingtable of contents

How can I remove the vertical spacing before each section in the table of contents from a 'article' documentclass?

Best Answer

You can redefine \l@section as implemented in article.cls and suppress (or comment out) the line \addvspace{1.0em \@plus\p@}% responsible for the extra space. Simply add these lines to the preamble of your document:

\makeatletter
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\makeatother