Menu

HowTo_multicols_toc

How to print a table of contents, list of figures or similar with two columns

Sometimes, in a single-column document, you want to automatically set directories such as the table of contents, the table of tables or the list of figures in multiple columns - usually in two columns. To do this, you could of course use something like:

\twocolumn
\tableofcontents
\listoffigures
\listoftables
\onecolumn

This actually works quite well with scrbook and scrreprt defaults, as the directories in these classes start a new page anyway. With scrartcl, however, the directories should not normally start a new page. In this case, the solution shown is out of the question. The same also applies if you use scrbook or scrreprt with the option listof=leveldown. However, even if you want the table of contents to start on a new page in this case, you do not want this for the other directories.

With scrartcl, you also usually do not want the directories to be output consecutively, i.e. the left-hand column starts with the table of contents and continues with the list of figures, which is then wrapped into the right-hand column, where the list of tables follows. Instead, the aim is for the table of contents to be output in two columns under the single-column heading, and the same for the list of figures below it, and so on. The two-column mode should therefore start under the heading and end after the content. The multicol package is best suited for this. With the multicols environment, it offers the option of starting the multi-column mode somewhere on a page and ending it somewhere on the same or a future page. The question is how to start the multi-column mode after the heading automatically set by \tableofcontents, \listoffigures etc. There are various tricks circulating on the Internet on how to write \begin{multicols}{2} and \end{multicols} in the respective auxiliary file. For \end{multicols}, something like \AtEndDocument{\addtocontents{...}{...}} is usually used. However, it is not even guaranteed that the \addtocontents statement will lead to an output at all. So the trick does not really work reliably.

It is much easier with the help of package tocbasic:

\usepackage{multicol}
\BeforeStartingTOC{\begin{multicols}{2}}
\AfterStartingTOC{\end{multicols}}

And all directories set via tocbasic are output in the desired form in two columns. The optional argument of \BeforeStartingTOC and \AfterStartingTOC can also be used to restrict the function to individual directories, for example

\usepackage{multicol}
\BeforeStartingTOC[toc]{\begin{multicols}{2}}
\AfterStartingTOC[toc]{\end{multicols}}

restricts the two-column feature to the table of contents.

Since scrbook, scrartcl and scrreprt use the tocbasic package for all three directories mentioned, this works for all three classes.

Unfortunately, just like the above-mentioned trick with \addtocontents, this can lead to a page break between the heading and the directory content. Here is an example:

\documentclass{scrartcl}

\usepackage{multicol}
\BeforeStartingTOC{\begin{multicols}{2}}
\AfterStartingTOC{\end{multicols}}

\usepackage{blindtext}

\begin{document}

\title{Title}
\author{Author}

\maketitle

\begin{abstract}
  \blindtext
\end{abstract}

\tableofcontents
\listoffigures

\blinddocument

\captionof{figure}{first example image}
\captionof{figure}{second example image}
\captionof{figure}{third example image}

\blinddocument

\end{document}

This problem cannot occur with scrbook and scrreprt without using the option listof=leveldown. The method is therefore generally a possible solution there.

To prevent such breaks, the multicols environment has an optional argument. The question now is how to get the directory heading into the optional argument. You could use \deftocheading to define a new heading format for each directory:

\documentclass{scrartcl}

\usepackage{multicol}
\deftocheading{toc}{\begin{multicols}{2}[\section*{#1}]}
\deftocheading{lof}{\begin{multicols}{2}[\section*{#1}]}
\deftocheading{lot}{\begin{multicols}{2}[\section*{#1}]}
\AfterStartingTOC{\end{multicols}}

\usepackage{blindtext}

\begin{document}

\title{Title}
\author{Author}

\maketitle

\begin{abstract}
  \blindtext
\end{abstract}

\tableofcontents
\listoffigures

\blinddocument

\captionof{figure}{first example image}
\captionof{figure}{second example image}
\captionof{figure}{third example image}

\blinddocument

\end{document}

However, it would be time-consuming to reproduce all the features offered by tocbasic or the KOMA-Script classes, such as the aforementioned listof=leveldown. It is easier to use the package needspace:

\documentclass{scrartcl}

\usepackage{multicol}
\usepackage{needspace}
\BeforeStartingTOC{\needspace{6\baselineskip}\begin{multicols}{2}}
\AfterStartingTOC{\end{multicols}}

\usepackage{blindtext}

\begin{document}

\title{Title}
\author{Author}

\maketitle

\begin{abstract}
  \blindtext
\end{abstract}

\tableofcontents
\listoffigures

\blinddocument

\captionof{figure}{first example image}
\captionof{figure}{second example image}
\captionof{figure}{third example image}

\blinddocument

\end{document}

The parameter of \needspace{...} can also be used to indirectly determine the minimum content of directories that must fit on the current page.

The use of this package does not interfere if you then switch to scrreprt or scrbook.


Related

Wiki (English): HowTo_ToCConfiguration

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.