0

Problem: In Table of Content, when both Chapter and Section numbers are 2-digits long, Section number sticks to title.

(I get the same issue in figure table, but I thought maybe that this should be a distinct question.)

All the rest is rendered as intended.

Here an anonymised working example including other stuff required by the rest of the document:

    %Preamble
\documentclass[11pt,a4paper,french,oneside,openright]{book}

\usepackage[left=28mm,right=34mm,top=37mm,bottom=44mm]{geometry}

\usepackage{comment}
\begin{comment}
%\usepackage{biblatex}
%\addbibresource{Pages/bibliography.bib}
\end{comment}

\usepackage{float}
\usepackage{afterpage}
\usepackage{lastpage}

\newcommand{\blankpage}{
    \null
    \thispagestyle{empty}
%    \addtocounter{page}{-1}
    \newpage
}
   
\newcommand{\startcontentpagestyle}{
    \pagestyle{fancy}
    \lfoot{"Shortened title..."}
    \rfoot{Page \thepage/\pageref{LastPage}}
    \renewcommand{\headrulewidth}{0.1pt}
    \renewcommand{\footrulewidth}{0.1pt}
    
\fancyhead{}
\lhead{\parbox[t]{0.5\textwidth}{\RaggedRight\rightmark\strut}}
\rhead{\parbox[t]{0.5\textwidth}{\RaggedLeft\leftmark\strut}}
\setlength{\headheight}{0\baselineskip}
\pagestyle{fancy}

    \fancypagestyle{plain}{%
      \fancyhf{}%
      \fancyfoot[L]{"Shortened title..."}%
      \fancyfoot[R]{Page \thepage/\pageref{LastPage}}%
      \renewcommand{\headrulewidth}{0pt}% Line at the header invisible
      \renewcommand{\footrulewidth}{0.1pt}% Line at the footer visible
    }   
}
    
\usepackage{fancyhdr}
\usepackage{ragged2e}
\usepackage{graphicx}
\graphicspath{ {./Images/} }

\usepackage{lipsum}

\usepackage{tocloft,calc}
%\renewcommand{\cftchappresnum}{Chapitre }
%\AtBeginDocument{\addtolength\cftchapnumwidth{\widthof{\bfseries Chapitre }}}

\title{Complete title}
\author{Author name}
\date{2021}

\usepackage{titlesec}

\usepackage[strings]{underscore}

% a command to tweak \addcontentsline for chapters
\newcommand{\chapitretocentry}{%
    \let\oldacl=\addcontentsline % save original definition
    \def\addcontentsline##1##2##3{% (re)define \addcontentsline
        \def\tempa{##1}\def\tempb{toc}% store ##1 and toc in temp vars
        \ifx\tempa\tempb % check if they are "equal"
            \def\tempa{##2}\def\tempb{chapter}%
            \ifx\tempa\tempb % check if ##2 is "equal" to chapter
                \oldacl{##1}{##2}{\chaptername\space ##3}% apply original \addcontentsline adding \chaptername
% in the other cases, just apply the original \addcontentsline
            \else
                \oldacl{##1}{##2}{##3}%
            \fi
        \else
            \oldacl{##1}{##2}{##3}%
        \fi
    }
}
\AtBeginDocument{\chapitretocentry} % invoke the command at the beginning


%Trying to get long titles in TOC
%Source: https://latex.org/forum/viewtopic.php?t=1267
\makeatletter
\newcommand*\std@chapter{}
\let\std@chapter=\@chapter
\renewcommand*\@chapter[2][]{\std@chapter[#2]{#2}\chaptermark{#1}}
\makeatother



\usepackage{datetime}
\usepackage[titletoc]{appendix}
\usepackage[french]{babel}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan
}

\input{Config/Figure_commands.tex}

\begin{document}
    \pagenumbering{gobble}
    \tableofcontents
    \newpage
    \listoffigures
    \listoftables
    \newpage
    \pagenumbering{arabic}
    \setcounter{chapter}{0}
    \setcounter{page}{16}
    \part{Introduction}
    \startcontentpagestyle
    
\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\chapter{Chapter 4}
\chapter{Chapter 5}
\chapter{Chapter 6}
\chapter{Chapter 7}
\chapter{Chapter 8}
\chapter{Chapter 9}
\chapter{Chapter 10}
\section{Chapter 10 - Section 1}
\section{Chapter 10 - Section 2}
\section{Chapter 10 - Section 3}
\section{Chapter 10 - Section 4}
\section{Chapter 10 - Section 5}
\section{Chapter 10 - Section 6}
\section{Chapter 10 - Section 7}
\section{Chapter 10 - Section 8}
\section{Chapter 10 - Section 9}
\section{Chapter 10 - Section 10}
\chapter{Chapter 11}
\section{Chapter 11 - Section 1}
\section{Chapter 11 - Section 2}
\section{Chapter 11 - Section 3}
\section{Chapter 11 - Section 4}
\section{Chapter 11 - Section 5}
\section{Chapter 11 - Section 6}
\section{Chapter 11 - Section 7}
\section{Chapter 11 - Section 8}
\section{Chapter 11 - Section 9}
\section{Chapter 11 - Section 10}
\end{document}


This question got closed and pointed to Roman numerals become “too wide” in table of contents but when I try to include \usepackage[tocindentauto]{tocstyle} I just get no change to document and all log disappears (blank log), so I don't know if the document is compiled at all. Try some of the other suggestion but didn't get any result. Please re-open.

4
  • This question got closed and pointed to tex.stackexchange.com/questions/7415/… but when I try to include \usepackage[tocindentauto]{tocstyle} I just get no change to document and all log disappears, so I don't know if the document is compiled at all. Try some of the other suggestion but didn't get any result. Please re-open.
    – TTT
    Aug 7, 2021 at 11:53
  • 1
    You use document class {book}, whereas, as it is written in the mentioned link, {tocstyle} works best with KOMA. In your case, you should have looked to an other answer under the same link, which tells you to include at least \usepackage[titles]{tocloft} \renewcommand*\cftsecnumwidth{3em} and may be also \renewcommand*\cftchapnumwidth{2em} to your preamble.
    – C. Peters
    Aug 7, 2021 at 14:19
  • Thank you. This indeed works/looks much better (I used 2 and 2.5 em though). (Maybe you should write it as an answer so I can check it as solution.)
    – TTT
    Aug 7, 2021 at 15:14
  • @TTT: Don't just follow the accepted answer. The accepted worked best for the original poster, but other answers there may also work for you (as you've now discovered). As such, this is still a duplicate.
    – Werner
    Aug 7, 2021 at 16:58

1 Answer 1

2

You use document class {book}, whereas, as it is written in the mentioned link, {tocstyle} works best with KOMA. In your case, you should have looked to an other answer under the same link, which tells you to include at least

\usepackage[titles]{tocloft}
 \renewcommand*\cftsecnumwidth{3em}% and may be also
 \renewcommand*\cftchapnumwidth{2em}%

to your preamble. (You can insert any dimension (width) that looks fine for you.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .