10

I use the tocloft package to design the Table of Contents. I want the part entries listed in one column and all the other entries such as chapter, section, subsection ... should be listed in two columns. For example, I want to have:

                                 Part I entry
------------------------------------ \hrule ---------------------------------
Chapter 1 chapter title ............ 1|Chapter 2 chapter title ............ 4
      1.1 section title............. 2|      2.1 section title............. 5
          1.1.1 subsection title ... 3|          2.1.1 subsection title ... 6


                                 Part 2 entry
------------------------------------ \hrule ---------------------------------
Chapter 3 chapter title ............ 7|Chapter 4 chapter title ........... 10
      3.1 section title............. 8|      4.1 section title............ 11
          3.1.1 subsection title ... 9|          4.1.1 subsection title .. 12

Em, the following is my MWE:


% !Mode:: "TeX:UTF-8"
\documentclass{book}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage{tikz}

\renewcommand\cftpartafterpnum{\nopagebreak\vspace{-.7em}\par\tikz\draw (0,-0.1) -- (0,0) -- (\linewidth,0) -- (\linewidth, -0.1);\vspace{-2em}}
\setlength{\cftpartnumwidth}{0pt}
\setlength{\cftbeforepartskip}{.6em}
\makeatletter
\renewcommand{\cftpartfont}{\bfseries%
  \def\numberline##1{\gdef\@temp@numberline{##1}}%
}
\renewcommand{\cftpartfillnum}[1]{%
    {}%
    {\centering\makebox[0em]{\cftpartpagefont}\cftpartafterpnum}%
}
\makeatother

% http://tex.stackexchange.com/questions/78980/how-to-emulate-titletoc-with-tocloft
\pretocmd{\part}{\addtocontents{toc}{\par}}{}{}
\pretocmd{\chapter}{\addtocontents{toc}{\par}}{}{}

\begin{document}
\tableofcontents

\part{Part Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\subsubsection{Subsubsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}

\part{Part Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}


\part{Part Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\section{Section Title}
\section{Section Title}
\subsubsection{Subsubsection Title}

\end{document} 

So how can I make all entries in two columns except the part ones just like the sample style presented Here.

Thanks.

PHoward
  • 269

1 Answers1

6

You need to insert the multicol environment definitions (start and end) at the appropriate locations: Immediately after \part you need \begin{multicol}{2} and immediately before \part you need \end{multicol}.

enter image description here

\documentclass{book}
\usepackage{tocloft,etoolbox,multicol,tikz}

\renewcommand\cftpartafterpnum{\nopagebreak\vspace{-.7em}\par\tikz\draw (0,-0.1) -- (0,0) -- (\linewidth,0) -- (\linewidth, -0.1);\vspace{-2em}}
\setlength{\cftbeforepartskip}{.6em}
\makeatletter
\renewcommand{\cftpartfont}{\bfseries\let\numberline\@gobble}
\renewcommand{\cftpartfillnum}[1]{%
    {}%
    {\centering\makebox[0em]{\cftpartpagefont}\cftpartafterpnum}%
}
\let\@oldendpart\@endpart
\renewcommand{\@endpart}{\addtocontents{toc}{\protect\begin{multicols}{2}}\@oldendpart}
\makeatother

\let\oldpart\part
\renewcommand{\part}{\ifnum\value{part}>0 \addtocontents{toc}{\protect\end{multicols}}\fi\oldpart}
\AtEndDocument{\ifnum\value{part}>0 \addtocontents{toc}{\protect\end{multicols}}\fi}

\begin{document}
\tableofcontents

\part{Part Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\subsubsection{Subsubsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\subsubsection{Subsubsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}

\part{Part Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\subsubsection{Subsubsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}

\part{Part Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\section{Section Title}
\section{Section Title}
\subsubsection{Subsubsection Title}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}
\subsubsection{Subsubsection Title}
\section{Section Title}
\section{Section Title}
\subsection{Subsection Title}

\end{document} 

The insertion of \begin{multicol}{2} is conditional on the fact that are not calling it the first time. Also, the insertion of \end{multicol} is done \AtEndDocument (also, conditional on the fact that you have at least one \part).

Werner
  • 603,163