[Tex/LaTex] Table of contents in two column, without multicol

table of contentstwo-column

Is there any way to make table of contents in two column without using multicol?

I added twocolumn in the document class, but the table of contents is still one column.

All solutions I found are using muitlcol.

However, using multicol in twocolumn mode gives me warning:

Package multicol Warning: May not work with the twocolumn option on input line 150.

So, I don't want to use multicol. Is there any way to make table of contents in two column without using multicol?

EDIT:
I am using book class

Best Answer

The \tableofcontents command from the standard book.cls checks whether twocolumn mode has been activated, uses onecolumn and sets a flag in order to restore to twocolumn after that.

\newcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }

I decided to use a new command, say \twocolumntoc which does not check. It is, of course, possible to put the twocolumn command into the new macro and the restoration with \onecolumn at the end of the command.

\documentclass{book}

\usepackage{pgffor}

\makeatletter
\newcommand{\twocolumntoc}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \@starttoc{toc}%
}
\makeatother

\setcounter{tocdepth}{4}

\begin{document}

\twocolumn
\twocolumntoc

\onecolumn

\foreach \x in {1,...,50}{%
\chapter{Chap \x}
\section{Foo section}
\subsection{Foo subsec}
\subsubsection{Foo subsecsec}
}
\end{document}

The pgffor package is only for quick generation of content in here.