LaTeX forum ⇒ GeneralAdditional 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.
User avatar
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm

Additional Rule after Part ToC Entry causes bad Page Breaks

Postby Bozack » Tue Dec 10, 2013 3:06 pm

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.
  1. \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:
  1. \documentclass{book}
  2.  
  3. \usepackage{tocloft}
  4.  
  5. \renewcommand{\cftpartafterpnum}{\cftparfillskip\\[-12pt]\hrule}
  6.  
  7. \begin{document}
  8. \tableofcontents
  9.  
  10. \clearpage
  11. \part{bla}
  12. \section{bla}
  13. \part{bla}
  14. \section{bla}
  15. \part{bla}
  16. \section{bla}
  17. \part{bla}
  18. \section{bla}
  19. \part{bla}
  20. \section{bla}
  21. \part{bla}
  22. \section{bla}
  23. \part{bla}
  24. \section{bla}
  25. \part{bla}
  26. \section{bla}
  27. \part{bla}
  28. \section{bla}
  29. \part{bla}
  30. \section{bla}
  31. \part{bla}
  32. \section{bla}
  33. \part{bla}
  34. \section{bla}
  35. \section{bla}
  36. \end{document}

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

while the top of the second page looks like
page2Capture.PNG
page2Capture.PNG (6.27 KiB) Viewed 3619 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:

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Thu Dec 12, 2013 8:26 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.
  1. \documentclass[11pt]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{tocloft}
  4. \usepackage{blindtext} % not for use in actual document
  5.  
  6. \renewcommand{\cftpartafterpnum}{%
  7. \par\nopagebreak% % begin new paragraph and prevent page break
  8. \vskip0.5ex\hrule% % draw horizontal rule after small vertical skip
  9. }
  10.  
  11. \begin{document}
  12. \tableofcontents
  13.  
  14. \part{Heading on level -1 (part)}
  15. \blinddocument % not for use in actual document
  16.  
  17. \part{Heading on level -1 (part)}
  18. \blinddocument % not for use in actual document
  19.  
  20. \part{Heading on level -1 (part)}
  21. \blinddocument % not for use in actual document
  22.  
  23. \part{Heading on level -1 (part)}
  24. \blinddocument % not for use in actual document
  25. \end{document}

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


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

User avatar
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm

Postby Bozack » Fri Dec 13, 2013 12:37 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
Capture3.png (3.5 KiB) Viewed 3315 times

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

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

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Fri Dec 13, 2013 5:05 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.
  1. \documentclass[11pt]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{tocloft}
  4. \usepackage{blindtext} % not for use in actual document
  5.  
  6. \renewcommand{\cftpartafterpnum}{%
  7. \strut\par\nopagebreak% % begin new paragraph and prevent page break
  8. \vskip0.25ex\hrule% % draw horizontal rule after small vertical skip
  9. }
  10.  
  11. \begin{document}
  12. \tableofcontents
  13.  
  14. \part{Part title}
  15. \blinddocument % not for use in actual document
  16.  
  17. \part{Heading on level -1 (part)}
  18. \blinddocument % not for use in actual document
  19. \end{document}
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

User avatar
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm

Postby Bozack » Fri Dec 13, 2013 10:17 pm

That is perfect! Thank you so much for your time! :D
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 7 guests