2

I want to send the table of content of a document containing only section and subsection titles. Sections of the document are empty, therefore, page numbers do not make sense at this stage. I get a big column of useless page numbers on the right.

Title ............. 3
Title ............. 3
Title ............. 3

I do not want to remove a few page numbers from the TOC numbering as asked here, here or here. But I want to remove all page numbers from the TOC. The table of content would look like this

Title ............. 
Title ............. 
Title ............. 

Or better, without the dots:

Title 
Title  
Title  

2 Answers2

4

Use tocloft. From its manual:

enter image description here enter image description here

A sample:

\documentclass{article}
\usepackage{tocloft}
\usepackage{blindtext}
 \cftpagenumbersoff{section}
 \cftpagenumbersoff{subsection}
 \cftpagenumbersoff{subsubsection}
\begin{document}
  \tableofcontents
  \Blinddocument
\end{document}

enter image description here


Now wondering how to publish the TOC only, but that's probably for another question.

Let us say the name of your .tex file is myfile.tex with the following content:

\documentclass{article}
\usepackage{blindtext}   % for demo only
\begin{document}
  \tableofcontents
  \Blinddocument
\end{document}

Compile this 2-3 times. This will generate an auxiliary file named myfile.toc.

Now prepare anothe .tex file name mytoc.toc, say, with the following contents:

\documentclass{article}
\begin{document}
  \input{myfile.toc} 
\end{document} 

Compile this to get only the toc of myfile.tex.

  • Since I am a nice guy (sometimes ;-)) (+1) –  Nov 02 '15 at 11:10
  • @ChristianHupfer: Today! They won't count anyway :) –  Nov 02 '15 at 11:11
  • Thanks @HarishKumar, I added \usepackage{tocloft}, \cftpagenumbersoff{part}, \cftpagenumbersoff{section}, \cftpagenumbersoff{subsection}, to the latex preamble. And I get the desired result. Now wondering how to publish the TOC only, but that's probably for another question. – Paul Rougieux Nov 02 '15 at 12:41
  • 1
    @Paul4forest Please see the update. –  Nov 03 '15 at 05:22
2

The entries for the ToC (and LoF, LoT etc.) are done with \addcontentsline, more precisely:

\def\addcontentsline#1#2#3{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}

If \thepage is removed from the \contentsline call, all page numbers will be dropped.

If the page numbers for particular structuring levels should be removed use tocloft and its \cftpagenumbersoff{section} command etc. (as Harish Kumar showed in his answer)

\documentclass{book}

\usepackage{xpatch}

\xpatchcmd{\addcontentsline}{\thepage}{}{}{}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\blinddocument


\end{document}

enter image description here

  • @HarishKumar: I am at home ;-) School holidays –  Nov 02 '15 at 11:11
  • @HarishKumar: No children (yet)... and I will grab all TikZ and tcolorbox questions then :-P –  Nov 02 '15 at 11:13
  • And how to avoid the dotted lines as well? I'm asking, because it looks strange: lines without an end. – Keks Dose Nov 02 '15 at 12:55
  • @KeksDose: The O.P. wanted to have them, see his post. –  Nov 02 '15 at 13:25
  • Yes, I know, but I am courious myself ! – Keks Dose Nov 02 '15 at 14:36
  • @KeksDose: The easiest way (without another package) (untested!): \renewcommand{\@dotsep}{10000} ;-) –  Nov 02 '15 at 21:35
  • @ChristianHupfer thanks, for your solution, in fact I am also happy without the dots. As in the solution provided by HarishKumar. – Paul Rougieux Nov 03 '15 at 07:46
  • @Paul4forest: If I would have known this I would have omitted them -- your question wasn't very clear then –  Nov 03 '15 at 08:50
  • My apologies @ChristianHupfer you are very right, my question wasn't clear. I was mostly frustrated by these page numbers. And both of your answers were really quick and satisfying. I posted the question before lunchtime, hoping I might get an answer in the afternoon. But within minutes, I had two replies. It surprised me, I expressed my surprise to a colleague at the lunch break. – Paul Rougieux Nov 03 '15 at 14:32