2

When using \part with tocloft (without fontspec) in pdflatex as suggested in the answer in this post Separate book into parts and chapters, I encounter a problem in the section numbering in the tableofcontents like this.

Contents

First Part

1 Chapter1

1 Sections1.1

1.1 Subsection1.1.1

2 Chapter2

1 Section2.1

1 Section2.2

1.1 Subsection2.2.1

Second part

3 Chapter3

2 Section3.1

2.1 Subsection3.1.1

The sectioning in the text however is fine.

Can someone help me out? Thanks.

The preamble is the following

\documentclass[a4paper,10pt]{book}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{inputenc}
\usepackage{tabularx}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{textcomp}
\usepackage{xpatch}
\usepackage{tikz}
\usepackage{tocloft}
\usepackage{inputenc}
\usepackage{xspace}
\usepackage{fancyhdr} 
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{}
\fancyhead[RE,LO]{\textcopyright~ Prints 2019}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{\thepage}

\everymath{\displaystyle}

\newtheorem{prop}{Proposition}[chapter]
\newtheorem{defn}{Definition}[chapter]
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[prop]{Corollary}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}[chapter]

\newcommand{\floorceil}[1]{\lceil #1 \rfloor}

\makeatletter
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother

\renewcommand{\cftpartfont}{\bfseries\Large\hrule}%add line above part
\renewcommand{\cftpartpagefont}{\bfseries}
\renewcommand{\cftbeforepartskip}{5mm}
\renewcommand{\cftpartafterpnum}{\\\hrule}%add line below part
\cftpagenumbersoff{part}%get rid of part page numbers
\renewcommand{\cftsecindent}{8mm}%control spacing between number and sec title
\renewcommand{\cftsecnumwidth}{4mm}%section indent
\renewcommand{\cftparskip}{4mm}%control line spacing

\begin{document}
\tableofcontents
\part{First part}
\chapter{Chapter1}
\section{Sections1.1}
\subsection{Subsection1.1.1}
\chapter{Chapter2}
\section{Section2.1}
\section{Section2.2}
\subsection{Subsection2.2.1}
\part{Second part}
\chapter{Chapter3}
\section{Section3.1}
\subsection{Subsection3.1.1}
\end{document}

A snapshot of the toc is here.toc1[![][1]]2

5
  • Welcome to TeX.SE! Please, as usual here, provide an MWE that reproduces your problem. An MWE should be as short as possible, start with \documentclass and end with \end{document}.
    – schtandard
    Commented Aug 9, 2019 at 7:07
  • I have added the preamble and hope it is done right. Commented Aug 9, 2019 at 7:21
  • Please describe the issue in words. Is it, e.g., that the section numbers and headers overlap?
    – Mico
    Commented Aug 9, 2019 at 7:55
  • If the issue overlaps the section numbers and headers, as @Mico pointed out, increase the section indent value from 4mm, for example, to 6mm. \renewcommand{\cftsecnumwidth}{6mm}
    – user31034
    Commented Aug 9, 2019 at 8:31
  • The section numbers does not start with Chapter number Section number but rather Part number. Commented Aug 9, 2019 at 8:41

1 Answer 1

2

Some comments and suggestions:

  • length parameters of the tocloft package should be modified via \setlength, not \renewcommand

  • consider replacing

    \renewcommand{\cftsecindent}{8mm}%control spacing between number and sec title
    \renewcommand{\cftsecnumwidth}{4mm}%section indent
    

    with

    \cftsetindents{chap}{0em}{1.5em}
    \cftsetindents{sec}{1.5em}{2em}
    \cftsetindents{subsec}{3.5em}{2.75em}
    

    You are obviously free to modify these settings to suit your preferences and typesetting needs.


enter image description here

\documentclass[a4paper,10pt]{book}
\usepackage{mathtools,amssymb,amsthm}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{textcomp}
\usepackage{xpatch}
\usepackage{tikz}
\usepackage{tocloft}
\usepackage{xspace}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{}
\fancyhead[RE,LO]{\textcopyright~ Prints 2019}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{\thepage}

\everymath{\displaystyle}

\newtheorem{prop}{Proposition}[chapter]
\newtheorem{defn}{Definition}[chapter]
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[prop]{Corollary}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}[chapter]

\newcommand{\floorceil}[1]{\lceil #1 \rfloor}

\makeatletter
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother

\renewcommand{\cftpartfont}{\hrule\bfseries\Large}%add line above part
\renewcommand{\cftpartpagefont}{\bfseries}
\setlength{\cftbeforepartskip}{5mm}
\renewcommand{\cftpartafterpnum}{\\\hrule}%add line below part
\cftpagenumbersoff{part}%no page numbers for part-level entries

%% commented out:
%\setlength{\cftsecindent}{8mm}% spacing between number and sec title
%\setlength{\cftsecnumwidth}{6mm}%section indent

%% new instructions:
\cftsetindents{chap}{0em}{1.5em}
\cftsetindents{sec}{1.5em}{2em}  % 1st length should be sum of lengths on preceding line
\cftsetindents{subsec}{3.5em}{2.75em}

\setlength{\cftparskip}{4mm}%control line spacing

\begin{document}
\tableofcontents

\part{First part}
\chapter{Chapter1}
\section{Section1.1}
\subsection{Subsection1.1.1}
\chapter{Chapter2}
\section{Section2.1}
\section{Section2.2}
\subsection{Subsection2.2.1}
\part{Second part}
\chapter{Chapter3}
\section{Section3.1}
\subsection{Subsection3.1.1}
\end{document}
3
  • Could it be the case that the package tocloft is not installed properly in my system as the same problem occurs after replacing with your code? Thanks anyway! Commented Aug 9, 2019 at 8:58
  • @markhaokip - Maybe we're talking past each other. What exactly does "the same problem occurs" entail? I had posted an earlier comment asking you to elaborate on the exact nature of the problem you were trying to solve, but I received no answer. Can you verify that you (a) removed the instructions \renewcommand{\cftsecindent}{8mm} and \renewcommand{\cftsecnumwidth}{4mm}, (b) inserted all three new \cftsetindents instructions shown in my answer, and (c) changed \renewcommand to \setlength where required and indicated?
    – Mico
    Commented Aug 9, 2019 at 9:04
  • 1
    It works, now. I run it on a new file and all is well. Thanks again, you're a life saver! Commented Aug 9, 2019 at 9:31

You must log in to answer this question.

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