0

I posted a question before regarding how to make a little space between the numbering of the subsection and the name of this subsection in TOC starting from the tenth subsection. The answers here suggest solutions. One of the best solution is using the commands

\usepackage[tocindentauto]{tocstyle}
\usetocstyle{KOMAlike}

In fact, this solves the problem and changes the style of the table of contents leaving a little space between the numbering and the titles of the subsections as desired. But, it creates another problem that is a space arose in the bottom of a single page of the pages of the table of contents!. Here is a screenshot of the problem:

enter image description here How can I fill this space with other items (that are already shifted to the next page) ?!. Here is my MWE:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{tocloft}
\usepackage[tocindentauto]{tocstyle}
\usetocstyle{KOMAlike}

\begin{document}
\tableofcontents

\end{document}
  • \enlargethispage*{1\baselineskip} if it happens on the first page of the table of contents. Or change the geometry of the pages corresponding to this table with \newgeometry{textheight=…} before calling the table of contents, and \restoregeometry at the end. Or slihghly reduce the interline skip in the table. – Bernard May 26 '17 at 0:21
  • I can not unfortunately change the geometry of the pages. Where I should add to command \enlargethispage*{1\baselineskip} precisely sir ? @Bernard – Hussein Eid May 26 '17 at 1:52
  • In any part of the code which corresponds to the page you want to enlarge. As it is for the table of contents, for which you do not type the text yourself, only a command, it can work only for the first page. As I didn't test it, please let us know if you have any difficulty in making it work. – Bernard May 26 '17 at 8:23
  • It does not work. I put it in the line following \tableofcontents but I got nothing. Can you test it please?!. Is there another solution? @Bernard – Hussein Eid May 26 '17 at 14:30
  • If you have to put it somewhere, it is just before \tableofcontents. Otherwise there's the solution with geometry (increasing temporarily the text height, then restoring the normal height), or reformatting the table of contents to have a smaller line skip (only for the table of contents). – Bernard May 26 '17 at 14:50
1

First of all: use at most one package to format the table of contents, i.e. either tocloft or tocstyle or tocbasic or ...

Unfortunaly the MWE does not show the issue. So the following is only a guess: Maybe subsection 9.1 is followed by subsection 9.2 and subsection 9.2.1.

Package tocstyle avoids page breaks between a sectioning level followed by a lower section level. Here lower section level means higher section level number. So there is no page break allowed between a section and the first subsection entry or between a subsection and the first subsubsection entry.

Note that package tocstyle is an alpha version and AFAIK this status will never change. The author suggests to use package tocbasic instead:

\usepackage{tocbasic}[2017/01/03]
\DeclareTOCStyleEntry[dynnumwidth]{tocline}{section}
\DeclareTOCStyleEntry[dynnumwidth]{tocline}{subsection}
\DeclareTOCStyleEntry[dynnumwidth]{tocline}{subsubsection}

tocbasic avoids the page breaks between a section entry and its first subsection too.

Example:

enter image description here

But you can change this behavior using option onstarthigherlevel=\LastTOCLevelWasSame (onstarthighersectionlevel refers to the section level number). Note that I do not recommend this, but it is possible:

\usepackage{tocbasic}[2017/01/03]
\DeclareTOCStyleEntry[dynnumwidth,onstarthigherlevel=\LastTOCLevelWasSame]{tocline}{section}
\DeclareTOCStyleEntry[dynnumwidth,onstarthigherlevel=\LastTOCLevelWasSame]{tocline}{subsection}
\DeclareTOCStyleEntry[dynnumwidth,onstarthigherlevel=\LastTOCLevelWasSame]{tocline}{subsubsection}

enter image description here

Code:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{tocbasic}[2017/01/03]
\DeclareTOCStyleEntry[dynnumwidth,onstarthigherlevel=\LastTOCLevelWasSame]{tocline}{section}
\DeclareTOCStyleEntry[dynnumwidth,onstarthigherlevel=\LastTOCLevelWasSame]{tocline}{subsection}
\DeclareTOCStyleEntry[dynnumwidth,onstarthigherlevel=\LastTOCLevelWasSame]{tocline}{subsubsection}

\usepackage{blindtext}% for dummy text
\usepackage{showframe}% to show the page layout
\begin{document}
\tableofcontents
\Blinddocument\Blinddocument\Blinddocument
\Blinddocument\Blinddocument\Blinddocument
\end{document}

If you want to use package tocloft then remove tocstyle and change the settings for the numwidths and indents in ToC manuelly:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{tocloft}
\renewcommand*\cftsecnumwidth{2em}
\renewcommand*\cftsubsecindent{2em}
\renewcommand*\cftsubsecnumwidth{2.8em}
\renewcommand*\cftsubsubsecindent{4.8em}

\usepackage{blindtext}% for dummy text
\usepackage{showframe}% to show the page layout
\begin{document}
\tableofcontents
\Blinddocument\Blinddocument\Blinddocument
\Blinddocument\Blinddocument\Blinddocument
\end{document}

enter image description here

  • This does not solve the problem. This solution left no space between the the last line in the first page of the table of contents and the page number. The number of the page does no longer exist. Besides, the same problem (discussed in the my question) arose in the next pages of the table of contents. – Hussein Eid May 29 '17 at 3:43
  • Did you test my example? Without loading tocloft? As you can see in the second picture, the text height is completly filled and the page number exists. Note: Do not load more than one package which affects the ToC. That means: use either tocloft or tocstyle or tocbasic. – esdd May 29 '17 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.