1

I want the \tableofcontents to produce only the list of the elements in form of a "true list", which mean I can type text on the same page before and after the list, and the list can be moved to another page.

I don't want the command to produce the title Table of Contents.

How can I do, or what should I add to my preamble?

Thank you in advance!

Edit I use book document class:

\documentclass{book}
\begin{document}
\tableofcontents
\chapter{Chapter 1}
\chapter{Chapter 2}
\end{document}
2
  • 2
    It depends mainly on the document class you are using and how it implements the \tableofcontents macro. Can you provide a minimal working example (MWE), please? Commented Nov 20, 2018 at 11:44
  • @PhelypeOleinik I edited my question.
    – user156344
    Commented Nov 20, 2018 at 11:57

2 Answers 2

3

The code for the book document class defines \tableofcontents as:

\newcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }

The first bit, \if@twocolumn ... \fi switches to one column mode in case you are using the twocolumn document class option. You probably don't want that if you want the contents to be part of the running text, so we can rule that out. This also allows us to remove the \if@restonecol\twocolumn\fi at the end, which switches back to \twocolumn if that's the case.

Next we have \chapter*{...}. This adds the chapter heading to the table of contents. You specifically asked to remove that, so... The \@mkboth in the \chapter* is responsible for the page headings saying TABLE OF CONTENTS. If you don't have a Table of contents chapter, you probably don't want that too, so we can rule it out.

We are now left with \@starttoc{toc}. This command basically does \@input{\jobname.toc}, so that's what we're looking for :)

Putting it in a document:

\documentclass{book}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\makeatletter
\@starttoc{toc}
\makeatother
\lipsum[2]
\chapter{Chapter 1}
\chapter{Chapter 2}
\end{document}

the first page shows

enter image description here


If you examine the .toc file you'll see it contains

\contentsline {chapter}{\numberline {1}Chapter 1}{3}
\contentsline {chapter}{\numberline {2}Chapter 2}{5}

Writing this directly to the .tex file would've worked as well.


Also, the \contentsline{chapter} command does \l@chapter which, if you look in book.cls you'll see it does a \vskip 1.0em \@plus\p@ before writing the content line. If you want to even the spacing before and after the \@starttoc you can use this same space:

\documentclass{book}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\makeatletter
\@starttoc{toc}
\vskip 1.0em \@plus\p@
\makeatother
\lipsum[2]
\chapter{Chapter 1}
\chapter{Chapter 2}
\end{document}
0
0

I probably shouldn't revive this old topic, but the following also works:

{\renewcommand{\chapter}[2]{}\tableofcontents}

Similar to this answer to another question, you can redefine what \chapter does for the table of contents only (same goes for any other type of title).

You must log in to answer this question.