0

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.

2 Answers 2

1

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

3
  • This looks reasonably simple. However, my TexStudio says 'package not found' after installling tocloft (Windows PC).
    – jvkloc
    Nov 18, 2021 at 19:24
  • @Jonne Then you have a problem with your installation. The tocloft package is included within the TeXLive distribution. Nov 18, 2021 at 19:26
  • Now it works. I restarted TexStudio.
    – jvkloc
    Nov 18, 2021 at 19:28
0

Since you are not numbering the section or subsection in the table of contents, I assumed you are adding them using \addcontentline

So you need to do 2 things for the last section and subsection

  1. suppress the page number, and
  2. delete the dots.

If you are using the book class remove \renewcommand*\l@section{...

c

\documentclass{article}

% adds dots for section in class article
\makeatletter
\renewcommand*\l@section{\@dottedtocline{1}{0.5em}{2.3em}}
\makeatother

\begin{document}
\tableofcontents
    
\clearpage
\section*{First}
\addcontentsline{toc}{section}{First}
\subsection*{First subsec}
\addcontentsline{toc}{subsection}{First sub}

\section*{Second}
\addcontentsline{toc}{section}{Second}
\subsection*{Second subsec}
\addcontentsline{toc}{subsection}{Second sub}

% supress page numbers => https://tex.stackexchange.com/a/9294/161015
\renewcommand*{\addcontentsline}[3]{\addtocontents{#1}{\protect\contentsline{#2}{#3}{}}}
% supress the dots => https://tex.stackexchange.com/a/71329/161015
\makeatletter
\addtocontents{toc}{\def\string\@dotsep{100}}
\makeatother
        
\section*{Third}
\addcontentsline{toc}{section}{Third}
\subsection*{Second subsec}
\addcontentsline{toc}{subsection}{Third sub}    
\subsection*{Third sub}
    
\end{document}

NOTE If this solution doesn't work for you, it may be because you are using another class and additional packages that modify the table of contents. If this is the case, post a minimal compilable example with its full preamble. (from \documentclass to \end{document})

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .