5

I'd like to add one or two lines of comments to the table of contents, in the space between the heading "Contents" and the table itself, and I'd like to have a margin of freedom for adjusting the distance of this text from the heading and/or from the list. Any hint? I'm working with the document class "book".

  • 1
    Welcome to Tex.SE. Please elaborate your answer by posting a minimal working example. – pushpen.paul Jun 16 '17 at 20:24
  • 1
    @pushpen.paul what do you not understand in that question? If it's only a minimal setup you can play with, see my answer. – Skillmon Jun 16 '17 at 20:27
8

You might use the \addtocontents macro:

\documentclass[]{book}

\addtocontents{toc}{\vspace{5cm}This is a note\vspace{4cm}\par}

\begin{document}
\tableofcontents

\chapter{foo}
\chapter{bar}
\end{document}
  • You probably want the \par before the \vspace. – TH. Jun 16 '17 at 20:15
  • @TH. it doesn't matter as far as I can tell. – Skillmon Jun 16 '17 at 20:15
  • Ah. I can never remember what the LaTeX vertical spacing commands do in horizontal mode. Looking at it, it looks like it ends up using a \vadjust when not in vertical mode. – TH. Jun 16 '17 at 20:26
  • @TH.: Yes, \vspace not in vertical mode results in \vadjust; yet the tokens specified in the argument of \addtocontents should be processed in vertical mode. – GuM Jun 16 '17 at 20:45
  • @Skillmon: Why \vspace*? – GuM Jun 16 '17 at 20:47
6

Another possibility: add the text to the definition of the table of contents

(the original definition is taken from book.cls l. 588ff)

\documentclass{book}

\usepackage{lipsum}

\makeatletter
\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \lipsum[2]% <- Add your text here
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }
\makeatother

\begin{document}

\tableofcontents

\chapter{bla}

\end{document}
  • +1! I like people who opposes the “there’s a package for that” philosophy! – GuM Jun 16 '17 at 21:04
  • 1
    @GustavoMezzetti I'm not opposed to packages, some are really helpful or would you really want to make all the coffee stains on your document by hand? :) – user36296 Jun 16 '17 at 21:19
  • I was joking, of course! Mine was just an innocent (or at least, I meant it so) pun on the fact that the tocloft package does exactly redefine the \tableofcontents command, albeit in a less class-specific manner. – GuM Jun 16 '17 at 21:24
  • @GustavoMezzetti Me too :) That's why I suggested such a useful example :) – user36296 Jun 16 '17 at 21:32
5

Another possibility is to use the tocloft package, which features a \cftaftertoctitle command that can be stretched a little bit beyond what it was intended for in order to provide the required addition:

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc} % unrelated to the problem, but I always load it
\usepackage{tocloft}
\usepackage{lipsum} % only for this example, generates "Lorem ipsum" text

\renewcommand*{\cftaftertoctitle}{%
    \par % necessary
    \nobreak\bigskip % for example
    \itshape % font changes are confined to the note
    This is a note after the title.
    \lipsum*[2]\par
    % \nobreak\vspace{18pt} % uncomment and modify as needed
}



\begin{document}

\tableofcontents

\chapter{Fake chapter title}
\lipsum[1]

\section{Fake section title}
\lipsum[2-8]

\section{Another fake title}
\lipsum[9-16]

\end{document}

This solution has the advantage of not requiring a pass through the .toc file…

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.