LaTeX forum ⇒ General ⇒ Additional Rule after Part ToC Entry causes bad Page Breaks Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm

Additional Rule after Part ToC Entry causes bad Page Breaks

I am working on my thesis (in the book class), and am using the tocloft package to make my table of contents pretty.

I would like to add a horizontal line beneath each Part section of the ToC, but here I run into a problem. I use this to add an \hrule after each part entry, and this looks great.
\renewcommand{\cftpartafterpnum}{\cftparfillskip\\[-12pt]\hrule}

However, when the ToC goes over more than one page, it happens that the entry is on one page and the line ends up on the next page.

Here is a minimal example showing what happens:
\documentclass{book} \usepackage{tocloft} \renewcommand{\cftpartafterpnum}{\cftparfillskip\\[-12pt]\hrule} \begin{document}   \tableofcontents    \clearpage   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \part{bla}   \section{bla}   \section{bla}\end{document}

This results in the bottom of the first page looking like
page1Capture.PNG (3.97 KiB) Viewed 3681 times

while the top of the second page looks like
page2Capture.PNG (6.27 KiB) Viewed 3681 times

Is there any way that the line can be forced to follow the part entry, instead of seemingly floating free on its own? Preferably the part entry should simply be moved to the next page along with the line.

I know it should be possible to fill in extra space in the ToC here and there, when I get closer to finishing the thesis and know how the sections will actually be positioned on the contents pages, but it would be really nice for this to simply happen automatically.
Last edited by Bozack on Sat Dec 14, 2013 1:15 am, edited 1 time in total.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 7 Professional 64bit, MikTeX 2.9, TeXnicCenter 2.0 beta 1 64bit

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
Your redefinition of \cftpartafterpnum seems to be the culprit. It requires to prevent the page break between the concerned ToC entry and the following rule. And according to the explanations in the tocloft manual I think that \cftparfillskip is fairly wrong here.

The below approach works quite nice so that you can simply write your document without having to bother about your ToC.
\documentclass[11pt]{book}\usepackage[T1]{fontenc}\usepackage{tocloft}\usepackage{blindtext}  % not for use in actual document \renewcommand{\cftpartafterpnum}{%   \par\nopagebreak%   % begin new paragraph and prevent page break   \vskip0.5ex\hrule%  % draw horizontal rule after small vertical skip} \begin{document}   \tableofcontents    \part{Heading on level -1 (part)}     \blinddocument  % not for use in actual document    \part{Heading on level -1 (part)}     \blinddocument  % not for use in actual document    \part{Heading on level -1 (part)}     \blinddocument  % not for use in actual document    \part{Heading on level -1 (part)}     \blinddocument  % not for use in actual document\end{document}

Click on "Open in writeLaTeX" in the head of the above code box to see the output instantly.

Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm
Ah, great solution! One thing that changes, though, is that now the line is a certain length below the text (as in, the actual extend of the letters) instead of being a length below the baseline of the text. This means that Part titles with "deep" letters (y,g,j, etc., anything that extends below the baseline) will have lines that are lower than otherwise, which to me is very visible:

Capture3.png (3.5 KiB) Viewed 3377 times

Sorry if I'm using the wrong words here, I'm not enough of a typographer to know what things are called

Do you think there is some alternative to the \vskip that will go from baseline instead of the bottom of the word?
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 7 Professional 64bit, MikTeX 2.9, TeXnicCenter 2.0 beta 1 64bit

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
I didn't take into account that a part heading of course can consist only of characters without descenders. So we need an invisible strut here to balance this.

Supplement the redefinition of \cftpartafterpnum with the \strut command to insert an invisible rule with a height of 0.7\baselineskip and a depth of 0.3\baselineskip. The vertical skip can then be reduced to 0.25ex in order not to have a too big gap between the heading and the rule.
\documentclass[11pt]{book}\usepackage[T1]{fontenc}\usepackage{tocloft}\usepackage{blindtext}  % not for use in actual document \renewcommand{\cftpartafterpnum}{%   \strut\par\nopagebreak%  % begin new paragraph and prevent page break   \vskip0.25ex\hrule%      % draw horizontal rule after small vertical skip} \begin{document}   \tableofcontents    \part{Part title}     \blinddocument  % not for use in actual document    \part{Heading on level -1 (part)}     \blinddocument  % not for use in actual document\end{document}
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm
That is perfect! Thank you so much for your time!
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 7 Professional 64bit, MikTeX 2.9, TeXnicCenter 2.0 beta 1 64bit

Return to “General”

Who is online

Users browsing this forum: No registered users and 5 guests