0

I have a question about modifying the table of content I want to divide it into three parts (here, part 2, part 3). For the first part, I have a book sample like the following:

\documentclass{book}

\usepackage[a5paper]{geometry} \usepackage{lipsum} \linespread{1.5}

\begin{document}

\tableofcontents \addtocontents{toc}{ \textbf{Title} \hfill \textbf{Page}\par}

\chapter{Spring}\lipsum[1-30] \section{Sp1}\lipsum[1-30] \section{Sp2}\lipsum[1-30] \section{Sp3}\lipsum[1-30] \section{Sp4}\lipsum[1-30] \section{Sp5}\lipsum[1-30] \section{Sp6}\lipsum[1-30] \section{Sp7}\lipsum[1-30] \section{Sp8}\lipsum[1-30] \section{Sp9}\lipsum[1-30]

\chapter{Summer} \section{Su1}\lipsum[1-30] \section{Su2}\lipsum[1-30] \section{Su3}\lipsum[1-30] \section{Su4}\lipsum[1-30] \section{Su5}\lipsum[1-30] \section{Su6}\lipsum[1-30] \section{Su7}\lipsum[1-30] \section{Su8}\lipsum[1-30] \section{Su9}\lipsum[1-30]

\chapter{Fall} \section{F1}\lipsum[1-30] \section{F2}\lipsum[1-30] \section{F3}\lipsum[1-30] \section{F4}\lipsum[1-30] \section{F5}\lipsum[1-30] \section{F6}\lipsum[1-30] \section{F7}\lipsum[1-30] \section{F8}\lipsum[1-30] \section{F9}\lipsum[1-30]

\chapter{Winter} \section{W1}\lipsum[1-30] \section{W2}\lipsum[1-30] \section{W3}\lipsum[1-30] \section{W4}\lipsum[1-30] \section{W5}\lipsum[1-30] \section{W6}\lipsum[1-30] \section{W7}\lipsum[1-30] \section{W8}\lipsum[1-30] \section{W9}\lipsum[1-30]

\end{document}

As is seen, I have added "title" and "page" on the top of the content (toc) and page columns. Since the toc is a multipage one, I want to repeat them as they are on the first page of the toc. How can it be figured out? Thanks

AYBRXQD
  • 737
  • If your toc is stable, e.g. if you are not adding new sections or change the formatting, you could manually add them, e.g. \addtocontents{toc}{ \textbf{Title} \hfill \textbf{Page}\par} \section{Su3} – samcarter_is_at_topanswers.xyz Mar 20 '23 at 15:54
  • Dear @samcarter_is_at_topanswers.xyz, I need it to be repeated automatically not manually. Thanks for your help. – AYBRXQD Mar 20 '23 at 16:02

2 Answers2

4

First of all: Adding such a line to every page of the table of contents does not make any sense, because everybody knows, that the left numbers + texts are titles and the right numbers are page numbers. So I would not recommend to add such a line. Moreover, I even would recommend to not add such a line.

With LaTeX from 2020/10/01 you can use the generic hook shipout/after to add the line after each output of a table of contents page. You also would have to add the line below the heading. And you would have to reset it after the end of the table of contents. With the KOMA-Script class scrbook instead of book you can use \AfterTOCHead for the initialization and \AfterStartingTOC for the deinitialization:

\documentclass[emulatestandardclasses,a5paper]{scrbook}
\usepackage{blindtext}
\newcommand*{\showtitlepageline}{}
\AfterTOCHead[toc]{%
  \renewcommand*{\showtitlepageline}{%
    \textbf{title}\hfill\textbf{page}\par\addvspace{\baselineskip}%
    \AddToHookNext{shipout/after}{\showtitlepageline}%
  }%
  \showtitlepageline
}

\AfterStartingTOC[toc]{% \let\showtitlepageline\relax \clearpage }

\begin{document}

\tableofcontents

\blinddocument\blinddocument\blinddocument\blinddocument \blinddocument\blinddocument\blinddocument\blinddocument

\end{document}

automatically add "title" and "page" to every page of table of contents


Note: This suggestion can be easily combined with the suggestions for your other questions.

\documentclass[emulatestandardclasses,a5paper]{scrbook}
\usepackage{xcolor}
\usepackage{blindtext}
\newcommand*{\showtitlepageline}{}
\AfterTOCHead[toc]{%
  \renewcommand*{\showtitlepageline}{%
    \textbf{title}\hfill\textbf{page}\par\addvspace{\baselineskip}%
    \AddToHookNext{shipout/after}{\showtitlepageline}%
  }%
  \showtitlepageline
}

\AfterStartingTOC[toc]{% \let\showtitlepageline\relax \cleardoublepage }

\BeforeTOCHead[toc]{% \let\raggedchapter\centering% centering the heading \setchapterpreamble[o]{\centering\color{red} a short text}% add a preamble above \pagestyle{plain}% no page header in the table of contents }

\begin{document}

\tableofcontents

\blinddocument\blinddocument\blinddocument\blinddocument \blinddocument\blinddocument\blinddocument\blinddocument

\end{document}

all together

Doing the same with the standard class book would be possible, but much more coding and hacky (as already shown).

cabohah
  • 11,455
0

This version uses afterpage. Note that the "header" is actually inside the text area.

\documentclass{book}

\usepackage[a5paper]{geometry} \usepackage{lipsum} \linespread{1.5} \usepackage{afterpage} \newif{\ifTOC}

\newcommand{\TOCheader}{\ifTOC\noindent\textbf{Title} \hfill \textbf{Page}\par \afterpage{\TOCheader}\fi}

\begin{document}

\afterpage{\global\TOCtrue\afterpage{\TOCheader}}% \tableofcontents \TOCfalse \addtocontents{toc}{\hspace{1.5em}\textbf{Title} \hfill \textbf{Page}\par}

\chapter{Spring}\lipsum[1-30] \section{Sp1}\lipsum[1-30] \section{Sp2}\lipsum[1-30] \section{Sp3}\lipsum[1-30] \section{Sp4}\lipsum[1-30] \section{Sp5}\lipsum[1-30] \section{Sp6}\lipsum[1-30] \section{Sp7}\lipsum[1-30] \section{Sp8}\lipsum[1-30] \section{Sp9}\lipsum[1-30]

\chapter{Summer} \section{Su1}\lipsum[1-30] \section{Su2}\lipsum[1-30] \section{Su3}\lipsum[1-30] \section{Su4}\lipsum[1-30] \section{Su5}\lipsum[1-30] \section{Su6}\lipsum[1-30] \section{Su7}\lipsum[1-30] \section{Su8}\lipsum[1-30] \section{Su9}\lipsum[1-30]

\chapter{Fall} \section{F1}\lipsum[1-30] \section{F2}\lipsum[1-30] \section{F3}\lipsum[1-30] \section{F4}\lipsum[1-30] \section{F5}\lipsum[1-30] \section{F6}\lipsum[1-30] \section{F7}\lipsum[1-30] \section{F8}\lipsum[1-30] \section{F9}\lipsum[1-30]

\chapter{Winter} \section{W1}\lipsum[1-30] \section{W2}\lipsum[1-30] \section{W3}\lipsum[1-30] \section{W4}\lipsum[1-30] \section{W5}\lipsum[1-30] \section{W6}\lipsum[1-30] \section{W7}\lipsum[1-30] \section{W8}\lipsum[1-30] \section{W9}\lipsum[1-30]

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120