TeX - LaTeX Asked on June 19, 2021
I have the following to modify table of contents spacing when using memoir
:
setlength{cftbeforechapterskip}{0.5em}
setlength{cftchapternumwidth}{10em}
What is the equivalent when using the book
class?
Use the tocloft
package.
documentclass{book}
usepackage{tocloft}
setlength{cftbeforechapskip}{0.5em}
setlength{cftchapnumwidth}{10em}
Answered by Peter Wilson on June 19, 2021
Here is a minimal example using memoir
:
documentclass{memoir}
setlength{cftbeforechapterskip}{0.5em}
setlength{cftchapternumwidth}{10em}
begin{document}
tableofcontents
chapter{A chapter}
section{A section}
chapter{Another chapter}
end{document}
Here is a replication of the output using tocloft
in the book
document class (note that chapter-level lengths for the ToC under tocloft
uses cftchap...
, not cftchapter...
as is used with memoir
):
documentclass{book}
usepackage{tocloft}
setlength{cftbeforechapskip}{0.5em}
setlength{cftchapnumwidth}{10em}
begin{document}
clearpage
addcontentsline{toc}{chapter}{contentsname}
tableofcontents
chapter{A chapter}
section{A section}
chapter{Another chapter}
end{document}
Without any packages, you'll have to change the definition of l@chapter
. Here's the original definition from book.cls
:
newcommand*l@chapter[2]{%
ifnum c@tocdepth >m@ne
addpenalty{-@highpenalty}%
vskip 1.0em @plusp@
setlength@tempdima{1.5em}%
begingroup
parindent z@ rightskip @pnumwidth
parfillskip -@pnumwidth
leavevmode bfseries
advanceleftskip@tempdima
hskip -leftskip
#1nobreakhfil
nobreakhb@xt@@pnumwidth{hss #2%
kern-p@kernp@}par
penalty@highpenalty
endgroup
fi}
Here's the updated definition to replicate the behaviour of memoir
and/or tocloft
:
documentclass{book}
makeatletter
renewcommand*l@chapter[2]{%
ifnum c@tocdepth >m@ne
addpenalty{-@highpenalty}%
vskip 0.5em% <----------------- Similar to cftbeforechapskip from tocloft
setlength@tempdima{10em}% <--- Similar to cftchapnumwidth from tocloft
begingroup
parindent z@ rightskip @pnumwidth
parfillskip -@pnumwidth
leavevmode bfseries
advanceleftskip@tempdima
hskip -leftskip
#1nobreakhfil
nobreakhb@xt@@pnumwidth{hss #2%
kern-p@kernp@}par
penalty@highpenalty
endgroup
fi}
makeatother
begin{document}
clearpage
addcontentsline{toc}{chapter}{contentsname}
tableofcontents
chapter{A chapter}
section{A section}
chapter{Another chapter}
end{document}
Answered by Werner on June 19, 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