[Tex/LaTex] Adding a sectioning level with titleclass and tocdepth

sectioningtable of contentstitlesec

I want to add a subchapter sectioning level, between chapter and section.
I use the \titleclass command from titlesec package.

According to titlesec documentation, \titleclass{\subchapter}{straight}[\chapter] should set the level of subchapter to 1, and increase by 1 the levels below (section of level 2, subsection of level 3, etc).

However, the following example :

\documentclass{book}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{titletoc}

\titleclass{\subchapter}{straight}[\chapter]
\newcounter{subchapter}
\titleformat{\subchapter}[block]{}{}{0pt}{}
\titlespacing{\subchapter}{1pc}{*4}{*2.3}
\titlecontents{subchapter}[1.5em]{}{}{\hspace*{-2.3em}}{\titlerule*[0.75pc]{.}\contentspage} %bad formatting, but only here to produce a content line in ToC

\begin{document}
\setcounter{tocdepth}{1}
\tableofcontents

\chapter{Chapter one}

\subchapter{Subchapter one}

\section{Section one}
\subsection{A subsection}

\section{Section two}

\end{document}

produces a ToC showing both subchapter and section, meaning that the level of section is still equal to 1.

I also tried to add

\makeatletter
\def\toclevel@section{2}
\makeatother

as suggested in How to add an extra level of sections with headings below \subsubsection,
but it does nothing.

What am I missing?

Note that for now, I do not care about the formatting of the ToC and can manage this by myself later, I am only interested in the levels of the different sectioning titles.

Best Answer

The basic command \titlecontents is defined in the titlesec package as (see p.14):

\titlecontents{〈section〉}[〈left〉]{〈above-code〉}{〈numbered-entry-format〉}{〈numberless-entry-format〉}{〈filler-page-format〉}[〈below-code〉

I your case the option {〈numbered-entry-format〉} is "empty" , that is, it seems to be undefined. Therefore, after compiling my output does not show any subchapter number:

enter image description here

\contentslabelor \thecontentslabel print the subchapter number:

  • \contentslabel{2.3em}:

    enter image description here

  • \thecontentslabel\enspace:

    enter image description here

Without defining the option {〈numbered-entry-format〉} but combining it with the macro \dottedcontents, it also prints the subchapter number:

enter image description here

Nevertheless, in all the cases there is a problem with the level; but the manual says (p. 10):

"If the chapter level is 0, then the subchapter one is 1; the levels below are increased by one (section is 2, subsection is 3, and so on)."

This issue is addressed in GitHub as \titleclass doesn't increase levels below and it stills open by Javier Bezos, the author of \titlsec.




The code:

\documentclass{book}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{titletoc}

\titleclass{\subchapter}{straight}[\chapter]
\newcounter{subchapter}
\titleformat{\subchapter}[block]{}{}{0pt}{}
\titlespacing{\subchapter}{1pc}{*4}{*2.3}

%------------ together
\titlecontents{subchapter}[1.5em]{}{}{\hspace*{-2.3em}}{\titlerule*[0.75pc]{.}\contentspage} %bad formatting, but only here to produce a content line in ToC
\dottedcontents{subchapter}[1cm]{}{2.3em}{1pc}
%------------

%------with \contentslabel ------
%\titlecontents{subchapter}[1.5em]{}{\contentslabel{2.3em}}{\hspace*{-2.3em}}{\titlerule*[0.75pc]{.}\contentspage}

%------with \thecontentslabel ------
%\titlecontents{subchapter}[1.5em]{}{\thecontentslabel\enspace}{\hspace*{-2.3em}}{\titlerule*[0.75pc]{.}\contentspage}

\begin{document}
    \setcounter{tocdepth}{1}
    \tableofcontents

    \chapter{Chapter one}

    \subchapter{Subchapter one}

    \section{Section one}
    \subsection{A subsection}

    \section{Section two}
\end{document}
Related Question