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  
3

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) – user31729 Nov 2 '15 at 11:10
  • @ChristianHupfer: Today! They won't count anyway :) – user11232 Nov 2 '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 2 '15 at 12:41
  • 1
    @Paul4forest Please see the update. – user11232 Nov 3 '15 at 5: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 – user31729 Nov 2 '15 at 11:11
  • @HarishKumar: No children (yet)... and I will grab all TikZ and tcolorbox questions then :-P – user31729 Nov 2 '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 2 '15 at 12:55
  • @KeksDose: The O.P. wanted to have them, see his post. – user31729 Nov 2 '15 at 13:25
  • Yes, I know, but I am courious myself ! – Keks Dose Nov 2 '15 at 14:36

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.