9

I'm trying to make Table of Contents in two columns, but I'd like to center the contents name.

Now I'm doing

\twocolumn
\tableofcontents

but these commands give something like this:

Contents name   section 3
section 1       section 4 
section 2       section 5

while I'd like to obtain something like this:

    Contents name
section 1   section 3
section 2   section 4 

I cant find out how can I achieve this...

Werner
  • 603,163
annndrey
  • 193
  • 3

1 Answers1

7

Because the documentclass is missing, I give an example for class report and for article. The redefinition for \tableofcontents merges the definitions of the original \tableofcontents with the definition for the environment theindex. The centering is done by smuggling in \centering.

Example for report:

\documentclass[twocolumn]{report}

\makeatletter
\renewcommand*{\tableofcontents}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \twocolumn[\@makeschapterhead{\centering\contentsname}]%
  \@mkboth{\MakeUppercase\contentsname}%
          {\MakeUppercase\contentsname}%
  \thispagestyle{plain}%
  \@starttoc{toc}%
  \if@restonecol
    \onecolumn
  \else
    \clearpage
  \fi
}
\makeatother

\begin{document}
\tableofcontents

\chapter{Foobar}
\section{Hello World}
\subsection{Subsection}
\addtocontents{toc}{\protect\newpage}
\chapter{Last chapter}
\section{Last section}

\end{document}

Result for report

Example for article:

\documentclass[twocolumn]{article}

\makeatletter
\renewcommand*{\tableofcontents}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
  \twocolumn[\section*{\centering\contentsname}]%
  \@mkboth{\MakeUppercase\contentsname}%
          {\MakeUppercase\contentsname}%
  \thispagestyle{plain}%
  \@starttoc{toc}%
  \if@restonecol
    \onecolumn
  \else
    \clearpage
  \fi
}
\makeatother

\begin{document}
\tableofcontents

\section{Foobar}
\subsection{Hello World}
\subsubsection{Subsubsection}
\addtocontents{toc}{\protect\newpage}
\section{Last section}
\subsection{Last subsection}

\end{document}
pluton
  • 16,421
Heiko Oberdiek
  • 271,626