4

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.

1

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}
| improve this answer | |
0

I've solved this issue if one uses the standard LaTeX \tableofcontents construction (rather than loading titletoc). My conclusion is that inserting a new section level via titlesec changes the level as far as secnumdepth is concerned, but doesn't affect the table of contents commands.

The following is my solution:

\documentclass{book}
\usepackage{titlesec}
%\usepackage{titletoc}

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

\makeatletter
\newcommand{\l@subchapter}{\@dottedtocline{1}{1.5em}{2.3em}}

% The following redefines the \l@section so that \tableofcontents thinks
% that a section has Level 2, rather than Level 1.
\renewcommand{\l@section}{\@dottedtocline{2}{1.5em}{2.3em}}

\makeatother

\setcounter{tocdepth}{1}

\begin{document}
\tableofcontents
\chapter{Chapter one}
\subchapter{Subchapter one}
\section{Section one}
\subsection{A subsection}
\section{Section two}

\end{document}

I don't know what the correction is if you use titletoc, but I presume it is analogous.

| improve this answer | |

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.