1

I have a few long section and subsection names in table of contents come dangerously close to page number. Their length is such that the section name consumes all of the space usually occupied by periods. It looks bad. Ideally, a page break would be forced if the space to be filled by periods fell below a threshold. One could just change the section names but not ideal.

The class being called is dalthesis.cls. A relevant post is here.

2 Answers2

1

A solution to this was proposed to a question I asked, (albeit I was worried also worried about if the page numbers became very large too) and improved in this answer, but I don't think it's fair to say your question is a duplicate, so I'll repeat/copy some of their answers here:

Set rightindent in the TOCStyleEntries from the tocbasic package:

\documentclass{extarticle}
\usepackage{lipsum}
\usepackage[nottoc]{tocbibind}

\usepackage{tocbasic} \DeclareTOCStyleEntries[ rightindent=10em,% <-- Adjust as you wish pagenumberbox=\pagenumberbox ]{tocline}{section,subsection,subsubsection,paragraph,subparagraph,figure,table} \newcommand*\pagenumberbox[1]{\mbox{\hspace{0.5em}#1}}

\begin{document} \tableofcontents \addtocontents{toc}{\sloppy} \pagenumbering{arabic} \section{Something} \subsection{Something else} \subsection{Some possibly very long title section that might just decide to span several lines in the table of contents. Why would someone write this} \end{document}

enter image description here

oliversm
  • 2,717
1

Another solution is to increase the space taken by the page numbers in the ToC

% tocpageprob2.tex  SE 550154
\documentclass{report}

\makeatletter \renewcommand{@pnumwidth}{3em} % also try with this commented out \makeatother

\begin{document} \tableofcontents

\chapter{A chapter} \section{Short section title} Some text. \section{Long section title that may get too close to the page number in the}% ToC} More text. \end{document}

Peter Wilson
  • 28,066