[Tex/LaTex] Add two column heading on table of contents

table of contents

How can I put "Chapter" and "Page" below Table of Contents title like shown in picture? And I also have to carry these into next pages in my thesis if toc is more than one page.Thanks,

And it would be great if they are not hyperlinked

Best Answer

My initial answer was written using etoc.

The main idea though, was taken over from karlkoeller answer: using afterpage. The difference is that the method now is compatible with a TOC on many pages.

I figured next that it could be done in a simpler manner. Thus, I provide here two codes: one not using etoc at all. But the formatting of the toc will have to be done by some package, like tocloft. The second uses etoc to facilitate both the OP's constraint on the chapter headline and some formatting customisation. This second code sample has a somewhat more complicated document body. And on this occasion one sees something is not perfect for the last (fourth) toc page. I have not yet investigated which aspect of afterpage is causing this.

% without etoc
\documentclass{book}
\usepackage[textheight=10cm]{geometry}% small page height for testing!
\usepackage{hyperref}
\usepackage{afterpage}

\newif\ifintoc

\newcommand*{\PrintChapterTocHeadline}
  {\hbox to \linewidth{\textbf{Chapter}\hfill\textbf{Page}}\bigskip
   \SetupNextPage}

\newcommand*{\SetupNextPage}
  {\afterpage {\ifintoc\PrintChapterTocHeadline\fi}}

\addtocontents{toc}{\protect\PrintChapterTocHeadline}

\begin{document}

\begingroup\intoctrue
\tableofcontents
\endgroup

\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}

\end{document} 

toc page 1

toc page 2

toc page 3

toc page 4


As this is done with Roman Numerals for chapters, some rather big spaces are used on the left.

% solution using etoc

\documentclass{book}
\usepackage[textheight=10cm]{geometry}
\usepackage{hyperref}
\usepackage{etoc}
\usepackage{afterpage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% doing the thing for the chapter  headline one each page.
%%%% here, using etoc.
\newif\ifintoc

\newcommand*{\PrintChapterTocHeadline}
  {\hbox to \linewidth{\textbf{Chapter}\hfill\textbf{Page}}\bigskip
   \afterpage {\ifintoc\PrintChapterTocHeadline\fi}}

% after title hook will take care of the first chapter headline
% nothing is written to the .toc file, hence other TOCs in the
% document can be done, not using that extra thing. Naturally
% the hook will have to be redefined
\renewcommand{\etocaftertitlehook}
             {\parindent 0pt 
              \leftskip  0cm 
              \rightskip \tocright
              \parfillskip -\rightskip
              \PrintChapterTocHeadline
              \intoctrue }
% etoc always typesets TOCs in a group. Thus the \ifintoc boolean
% will be false after the TOC completes.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Now using etoc also to customize the formatting itself.
%%%% I take this opportunity to write down some rather general
%%%% etoc line style definitions, for a look somewhat like the
%%%% standard looks, but customisable.

%%%% some dimensions are hard-coded, but for some I already define
%%%% associated lengths

\newlength{\tocright}
\setlength{\tocright}{0.75cm}

\newlength{\toclefti}
\setlength{\toclefti}{1.25cm}
\newlength{\tocleftii}
\setlength{\tocleftii}{2.75cm}
\newlength{\tocleftiii}
\setlength{\tocleftiii}{4.25cm}

% Code for page numbers on the right side.

\renewcommand*\etoctoclineleaders
 {\hbox{\normalfont\normalsize\hbox to .6ex {\hss.\hss}}}

\newcommand*{\EndParWithPagenoInMarginAndLeaders}
 {\nobreak\leaders\etoctoclineleaders\hfill
 \nobreak\makebox[\tocright][r]{\mdseries\normalsize\etocpage}%
 \par }

% version with no dot leaders:
\newcommand*{\EndParWithPagenoInMargin}
 {\nobreak\hfill
 \nobreak\makebox[\tocright][r]{\mdseries\normalsize\etocpage}%
 \par}

\etocsetstyle{chapter}
{}
{\leavevmode\leftskip \toclefti }
{\llap{\makebox[\toclefti][l]{\bfseries\etocnumber.}}%
 \etoclink{\bfseries\MakeUppercase{\etocthename}}% roman uppercase
 \EndParWithPagenoInMargin}
{}

\etocsetstyle {section}
{}
{\leavevmode\leftskip \tocleftii }
{\llap{\makebox[\dimexpr\tocleftii-\toclefti\relax][l]{\etocnumber.}}%
 \textsc{\etocname}% small caps
 \EndParWithPagenoInMarginAndLeaders}
{\medskip}

\etocsetstyle {subsection}
{}
{\leavevmode\leftskip \tocleftiii }
{\llap{\makebox[\dimexpr\tocleftiii-\tocleftii\relax][l]{\etocnumber.}}%
 \etocname
 \EndParWithPagenoInMarginAndLeaders}
{\smallskip}

%\renewcommand*{\etoctoprule}{\hrule height 0pt\relax}
%\etocruledstyle [1]{\MakeUppercase{\contentsname}}
\etocsettocstyle
  {\hbox to \linewidth{\hss \MakeUppercase{\contentsname}\hss}\bigskip}
  {}


\renewcommand{\thechapter}{\Roman{chapter}}

\begin{document}

\tableofcontents

\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}

\end{document} 

toc page 1

toc page 2

toc page 3

toc page 4

Related Question