Remove the page number(s) of one section (and its subsections) from ToC of article document

page-numberingtable of contents

I want to remove page numbers of the last section and its subsections from an article document's table of contents. I have gone through several questions and answers about this topic and ended up breaking my document. Luckily I had a previous version of my thesis saved in the morning. At the moment I have

Section ............ 1
  subsection ....... 2
Section ............ 4
  subsection ....... 6
Section ............ 8
  subsection ....... 9

in my table of contents and I want

Section ............ 1
  subsection ....... 2
Section ............ 4
  subsection ....... 6
Section 
  subsection 

instead. All the help appreciated.

Best Answer

Use the tocloft package for controlling the ToC (and LoF and LoT).

% sectocprob.tex  SE 623057

\documentclass{article}

\usepackage{tocloft}

\begin{document}
\tableofcontents
\section{First section}
\subsection{A subsection}
\section{Second section}
\subsection{B subsection}
%% add into the ToC
\addtocontents{toc}{\cftpagenumbersoff{sec}} % no section page numbers 
\addtocontents{toc}{\cftpagenumbersoff{subsec}} % no subsection page numbers
\section{Third section}
\subsection{C subsection}
\end{document}

enter image description here

Related Question