TransWikia.com

How to customize line spacing on the ToC

TeX - LaTeX Asked on October 16, 2020

I’ve googled related to this problem. Most of them only discuss about consistent line spacing on the ToC.

So, I want my ToC to exactly look like this. By default, we know the space between chapter and section shorter than the space between chapter to chapter. If I can, as shown on the image link description above, I want The gap between ToC title and list contents has 4 line spacing, the first part has 0.5 line spacing as well as the line spacing of the second part and the third part, and the gap between each part has 3 line spacing.

On the second part, I want the space between chapter and section has 0.5 line spacing as well, so there is no default short space between chapter and section anymore. Please note and notice that my image link on the second part might have difference as I described here, that is the space between the chapter and the section.

So, this is my attempt:

documentclass[a4paper,12pt,oneside,openany]{book}
usepackage[a4paper, inner=4cm, outer=3cm, top=4cm, bottom=3cm]{geometry}
usepackage{blindtext}
usepackage{fancyhdr}
usepackage{titlesec}
usepackage{setspace}
usepackage[titles]{tocloft}
usepackage{tocbibind}
fancyhf{}
cfoot{thepage}
linespread{1.5}
pagestyle{plain}
renewcommandcftchapdotsep{cftdotsep}
titleformat{chapter}[display]
    {normalfontbfseriescentering}
    {chaptertitlename thechapter}{12pt}{}
titlespacing*{chapter}{0pt}{10pt}{40pt}

addtocontents{toc}{protectnullprotecthfill{Pages}protectpar}
setlengthparindent{1.25cm} 
begin{document}

clearpage
thispagestyle{empty}

frontmatter 

pagestyle{fancy}   
renewcommand{headrulewidth}{0pt}

%PART ONE:
chapter*{DEDICATION}
addcontentsline{toc}{chapter}{textbf{DEDICATION}}
blindtext
chapter*{ABSTRACT}
addcontentsline{toc}{chapter}{textbf{ABSTRACT}}
blindtext
chapter*{PREFACE}
addcontentsline{toc}{chapter}{textbf{PREFACE}}
blindtext

begin{spacing}{0.1}

tableofcontents
listoffigures
listoftables

end{spacing}

mainmatter %

%PART TWO:
chapter*{CHAPTER 1 HELLO}
addcontentsline{toc}{chapter}{textbf{HELLO}}
blindtext
section{HELLO 2}
blindtext
section{HELLO 3}
blindtext
chapter*{CHAPTER 2 HELLO 4}
addcontentsline{toc}{chapter}{textbf{HELLO}}
blindtext
section{HELLO 5}
blindtext
section{HELLO 6}
blindtext

%PART THREE:
chapter*{APPENDIX}
addcontentsline{toc}{chapter}{textbf{APPENDIX}}
blindtext
chapter*{VIT}
addcontentsline{toc}{chapter}{textbf{VIT}}
blindtext

end{document}

One Answer

I have modified your MWE to hopefully give the vertical spacing that you want in the ToC.

% tocspaceprob.tex SE 556782
documentclass[a4paper,12pt,oneside,openany]{book}
usepackage[a4paper, inner=4cm, outer=3cm, top=4cm, bottom=3cm]{geometry}
usepackage{blindtext}
usepackage{fancyhdr}
usepackage{titlesec}
usepackage{setspace}
usepackage[titles]{tocloft}
usepackage{tocbibind}
fancyhf{}
cfoot{thepage}
linespread{1.5}
pagestyle{plain}
renewcommandcftchapdotsep{cftdotsep}
titleformat{chapter}[display]
    {normalfontbfseriescentering}
    {chaptertitlename thechapter}{12pt}{}
titlespacing*{chapter}{0pt}{10pt}{40pt}

addtocontents{toc}{protectnullprotecthfill{Pages}protectpar}
setlengthparindent{1.25cm} 
begin{document}

clearpage
thispagestyle{empty}

frontmatter 

pagestyle{fancy}   
renewcommand{headrulewidth}{0pt}

%PART ONE:
chapter{DEDICATION}   %%% use chapter, not chapter* in frontmatter 
%addcontentsline{toc}{chapter}{textbf{DEDICATION}}
addtocontents{toc}{setlength{cftbeforechapskip}{4pt}} % change vertical space befor chapters in ToC
blindtext
chapter{ABSTRACT}
%addcontentsline{toc}{chapter}{textbf{ABSTRACT}}
blindtext
chapter{PREFACE}
%addcontentsline{toc}{chapter}{textbf{PREFACE}}
blindtext

begin{spacing}{0.1}

tableofcontents
listoffigures
listoftables

end{spacing}

mainmatter %

%PART TWO:
addtocontents{toc}{setlength{cftbeforechapskip}{12pt}} % change vertical space before chapters in ToC
%chapter*{CHAPTER 1 HELLO}
%addcontentsline{toc}{chapter}{textbf{HELLO}}
chapter{HELLO}blindtext
section{HELLO 2}
blindtext
section{HELLO 3}
blindtext
chapter*{CHAPTER 2 HELLO 4}
addcontentsline{toc}{chapter}{textbf{HELLO}}
blindtext
section{HELLO 5}
blindtext
section{HELLO 6}
blindtext

%PART THREE:
chapter*{APPENDIX}
addcontentsline{toc}{chapter}{textbf{APPENDIX}}
addtocontents{toc}{setlength{cftbeforechapskip}{4pt}} % another space change
blindtext
chapter*{VIT}
addcontentsline{toc}{chapter}{textbf{VIT}}
blindtext

end{document}

I think that your code is much more involved than it need be. For instance using chapter instead of chapter* ... addcontents... in the frontmatter gives you the entries you want in the ToC.. There are ways of putting CHAPTER before chapter titles in the ToC without having to use chapter* with the chapter number and title, which of course messes up the section numbering.

I think that you would do well to ask questions about these (one per problem).

Correct answer by Peter Wilson on October 16, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP