TeX - LaTeX Asked on January 24, 2021
Is it possible to get it without using package titletoc
? I’m using special chapter style which doesn’t work with this package.
There are so many options... without further information, one possible option would be to use the setspace
package and one of its commands of environments; for example,
documentclass{report}
usepackage{setspace}
begin{document}
doublespacing
tableofcontents
singlespacing
chapter{Test Chapter One}
section{Test Section One One}
section{Test Section One Two}
chapter{Test Chapter Two}
section{Test Section Two One}
section{Test Section Two Two}
end{document}
This approach will increase evenly the space between all sectional units. The following three options allow you to control separately the spacing for each group of sectional units.
Another option would be to use the tocloft
package and redefine the cftXafterpnum
family of commands:
documentclass{report}
usepackage{tocloft}
renewcommandcftchapafterpnum{vskip10pt}
renewcommandcftsecafterpnum{vskip15pt}
begin{document}
tableofcontents
chapter{Test Chapter One}
section{Test Section One One}
section{Test Section One Two}
chapter{Test Chapter Two}
section{Test Section Two One}
section{Test Section Two Two}
end{document}
Yet another option, this time using the etoolbox
package to patch the sectional units commands to add vertical space to the ToC:
documentclass{report}
usepackage{etoolbox}
makeatletter
pretocmd{chapter}{addtocontents{toc}{protectaddvspace{15p@}}}{}{}
pretocmd{section}{addtocontents{toc}{protectaddvspace{5p@}}}{}{}
makeatother
begin{document}
tableofcontents
chapter{Test Chapter One}
section{Test Section One One}
section{Test Section One Two}
chapter{Test Chapter Two}
section{Test Section Two One}
section{Test Section Two Two}
end{document}
A fourth option not requiring any packages would be to redefine the chapter
and section
commands as implemented in the used document class to add the vertical space to the ToC; an example with report
:
documentclass{report}
makeatletter
renewcommandchapter{addtocontents{toc}{protectaddvspace{5p@}}%
if@openrightcleardoublepageelseclearpagefi
thispagestyle{plain}%
global@topnumz@
@afterindentfalse
secdef@chapter@schapter}
renewcommandsection{addtocontents{toc}{protectaddvspace{20p@}}%
@startsection {section}{1}{z@}%
{-3.5ex @plus -1ex @minus -.2ex}%
{2.3ex @plus.2ex}%
{normalfontLargebfseries}}
makeatother
begin{document}
tableofcontents
chapter{Test Chapter One}
section{Test Section One}
section{Test Section Two}
chapter{Test Chapter One}
section{Test Section One}
section{Test Section Two}
end{document}
Correct answer by Gonzalo Medina on January 24, 2021
While the other suggestions so far allow increasing the line spacing of the Table of Contents, it seems they don't allow decreasing it, for example to fit a ToC on one page.
A simple
renewcommand{baselinestretch}{0.75}normalsize
tableofcontents
renewcommand{baselinestretch}{1.0}normalsize
will allow setting any line spacing.
It might be necessary to find out what your baselinestretch size is by default as the style seems to set this.
Answered by kjyv on January 24, 2021
Using tocloft, you can also add the following in your preamble to add spacing before a section entry:
usepackage{tocloft}
setlength{cftbeforesecskip}{6pt}
This complements Gonzalo's Answer in where he shows how to add spacing after a section entry: that can be undesirable in case you have subsections following a section. The tocloft's manual has many other options that can be used to manipulate other types of entries in the TOC.
Answered by Rudy Matela on January 24, 2021
Another global solution for reducing spacing, for cases where kjyv's local solution didn't work or caused trouble with line spacing in general is
renewcommandcftsecafterpnum{ vspace{-20pt}}
which worked for me while
renewcommandcftchapafterpnum{vskip-10pt}
didn't do anything.
Answered by ok_X on January 24, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP