3

I have a document that contains a multicolumn ToC made with

\usepackage[toc]{multitoc}
\renewcommand*{\multicolumntoc}{3}

I use the following command to make chapters and add them to the ToC, as I do not want chapter numbers to show up anywhere:

\newcommand{\myChapter}[1]{
  \chapter*{#1}
  \addcontentsline{toc}{chapter}{#1}
}

I want to add a line under each chapter heading in this ToC, but I simply cannot figure out how to do it. It should end up looking like this:

Chapter 1               1.1.3 Subsection        2.1.1 Subsection
-----------------                               2.1.2 Subsection
1.1 Section             Chapter 2
1.1.1 Subsection        -----------------
1.1.2 Subsection        2.1 Section

I have looked at the tocloft package and it gives an example for parts:

\part{Part title}
\addtocontents{toc}{\protect\mbox{}\protect\hrulefill\par}

This works, but I am interested in doing it for chapters, not parts. I have looked at Overfull hbox (in the middle of page) in ToC with tocloft package and cftchapaftersnum and How to change the style of ToC and \chapter? and followed the answers, without success. The line simply does not show up.

Can anyone tell me how I can make these lines?

3

You can use \addtocontents to add the rule:

\documentclass{book}
\usepackage[toc]{multitoc}

\renewcommand*{\multicolumntoc}{3}

\newcommand{\myChapter}[1]{%
  \chapter*{#1}%
  \addcontentsline{toc}{chapter}{#1}%
  \addtocontents{toc}{\vskip-6pt\par\noindent\protect\hrulefill\par}
}

\begin{document}

\tableofcontents

\myChapter{A test chapter}
\addtocontents{toc}{}
\section{A test section}
\section{A test section}
\section{A test section}
\section{A test section}
\section{A test section}
\myChapter{A test chapter}
\section{A test section}
\section{A test section}
\section{A test section}
\myChapter{A test chapter}
\section{A test section}
\section{A test section}
\section{A test section}

\end{document}

enter image description here

Something that I don't quite understand is that you don't want chapter number to appear, but your example shows the chapter counter before the sections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.