0

This question is an extension of the one posed in How to Selectively Turn Chapter Page Numbers Off in the Table of Contents

I am using dotfill for chapter entries in the TOC; however, I would like to be able to selectively turn it off; for example, in this MWE:

\documentclass{book}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\dotfill}
\begin{document}
    \tableofcontents    
    \newpage
  
    \chapter*{CHAPTER 1}        
    \addcontentsline{toc}{chapter}{CHAPTER 1}   
    
    \renewcommand{\cftchapleader}{}
    
    \chapter*{CHAPTER 2}        
    \addtocontents{toc}{\protect\contentsline{chapter}{CHAPTER 2}{}{}\par} 
    
    \renewcommand{\cftchapleader}{\dotfill}
    
    \chapter*{CHAPTER 3}        
    \addcontentsline{toc}{chapter}{CHAPTER 3}
\end{document}

I would like to eliminate the dotfill for the Chapter 2 entry only.

However, the above code does not do this; the TOC output being:

enter image description here

How may I modify the above code to eliminate both the page number and the dotfill for the Chapter 2 entry only?

1 Answer 1

1

Try this code.

b

\documentclass{book}
\usepackage{tocloft}
\renewcommand{\cftchapleader}{\dotfill}
    
%************************************* added <<<<   
\setlength{\cftbeforesubparaskip}{1.0em plus 1pt} 
\renewcommand{\cftsubparafont}{\bfseries} 
\setlength{\cftsubparaindent}{0em}
\renewcommand{\cftsubparadotsep}{\cftnodots}
\setcounter{tocdepth}{5}
%*************************************  

\begin{document}
    \tableofcontents    
    \newpage

    \chapter*{CHAPTER 1}        
    \addcontentsline{toc}{chapter}{CHAPTER 1}   
    
    
    \chapter*{CHAPTER 2}        
    \addtocontents{toc}{\protect\contentsline{subparagraph}{CHAPTER 2}{}{}} % changed  use subparagraph instead of chapter
        
    \chapter*{CHAPTER 3}        
    \addcontentsline{toc}{chapter}{CHAPTER 3}

\end{document}

The line added to the ToC uses subparagraph (hardly used in a book) instead of chapter to supress the dots. It requires to set the font size and space above of the chapter entries.

OPTION

If you don use \part in your document it is possible to use

%************************************* added <<<<       
\setlength{\cftbeforepartskip}{1.0em plus 1pt} % added <<<<<<
\renewcommand{\cftpartfont}{\bfseries} % added <<<<<<   
%************************************* 

and

\addtocontents{toc}{\protect\contentsline{part}{CHAPTER 2}{}{}} %   use part instead of chapter
4
  • Thank you kindly for this helpful answer.
    – DDS
    Commented Dec 12, 2022 at 18:21
  • I must have a strange actual document; when I run your edited answer as is---it seems to work fine. However, when I incorporate it into my actual document---I have problems. Perhaps I did not comment everything out from the first answer and, perhaps, a conflict results. I am now running my document with your original answer, customized a little bit---and it gives me what I am looking for except for some extra vertical space---which I'm sure I can take care of. By itself, your first answer seems to work perfectly. Any problems, I'm sure, are the result of conflicts caused on my end.
    – DDS
    Commented Dec 12, 2022 at 20:40
  • @jean-marie A vertical space before CHAPTER 2? Commented Dec 12, 2022 at 20:55
  • Yes; not a problem with your code I'm sure, because your answer gives desired spacing. The problem must be with some kind of a conflict on my end. Without knowing the reason why, I've taken care of it by adding some negative vertical space to the TOC after the entry.
    – DDS
    Commented Dec 12, 2022 at 21:07

You must log in to answer this question.

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