3

I am trying to use subsubsubsection on my report, and I using a code that was given on this website.

On below my MWE :

\documentclass[a4paper,11pt,french]{report}
\usepackage[francais]{babel}

\usepackage{titlesec}
\titleclass{\subsubsubsection}{straight}[\subsection]

\newcounter{subsubsubsection}
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered

\titleformat{\subsubsubsection}
  {\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
  {3.25ex \@plus1ex \@minus.2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{6}{\parindent}%
  {3.25ex \@plus1ex \@minus .2ex}%
  {-1em}%
  {\normalfont\normalsize\bfseries}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}
\def\toclevel@paragraph{6}
\def\l@subsubsubsection{\@dottedtocline{4}{10em}{5em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\def\l@subparagraph{\@dottedtocline{6}{14em}{6em}}
\makeatother

\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

\begin{document}

\tableofcontents

\pagebreak

\section{test}
\subsubsubsection{test11}
\subsubsubsection{test12}
\subsubsubsection{test13}

\section{test2}
\subsubsubsection{test21}
\subsubsubsection{test22}
\subsubsubsection{test23}

\end{document}

As you will notice, the subsubsubsection is not reset between these 2 sections.

How can I fix it please ?

How can I fix it please ? Thanks in advance for your help.

  • 1
    I do not know about titlesec new sections, but it should read \newcounter{subsubsubsection}[subsubsection] since this triggers the resetting of the counter a level below subsubsection. – user31729 Feb 20 '14 at 10:09
  • 1
    By the way, I am not sure about adding another section level enables readability of such a document. I never needed paragraphs etc., but this is a matter of taste and not a dogma. – user31729 Feb 20 '14 at 10:12
  • 1
    @Christian : I tried your proposal, but the counting wasn't reset neither. Concerning the readability, I understand your point, but I actually need to use these \subsubsubsections anyway. I am not looking for another way for doing it, only looking on a way to fix my issue. Thank you anyway for trying to help me. – oursay Feb 20 '14 at 10:15
  • 3
    You do not need to define a subsubsubsection counter, LaTeX report class already has two more levels of section heading defined below subsubsection, namely paragraph and subparagraph these are already set up to reset and have correct level in the table of contents etc. – David Carlisle Feb 20 '14 at 12:43
6

The subsubsubsection counter is reset at subsubsection. In your example the subsubsection counter never changed. (It remains always at zero.)

(More precisely, the reset command is only triggered when \stepcounter or \refstepcounter is called on the parent counter. As no \subsubsection command was ever issued, the counter is never step-increased, and the reset command never called.)

You can see the problem even without defining your own new section level. If you compile the following MWE:

\documentclass{article}
\begin{document}

\section{Test}
\subsubsection{test2}
\section{test3}
\subsubsection{test4}
\subsection{test 5}
\subsubsection{test6}
\end{document}

You will see that test2 is labeled 1.0.1 and test4 is labeled 2.0.2. But once you increment the subsection counter (when I put in test 5), the counter now behaves properly: test6 is 2.1.1.

This doesn't happen just with sectioning commands, by the way. If you use the \numberwithin command from the AMS packages to set the level for equations, or use the amsthm commands to tie theorem numbering to section levels, you should never tie the resetting to a counter that cannot be reliably incremented.

A possible work-around is given here: in your preamble add

\makeatletter
\@addtoreset{subsubsubsection}{section}
\@addtoreset{subsubsubsection}{subsection}
\makeatother

this will make increasing sections and subsections both also trigger the reset code.

  • 1
    thank you very much for these very clear explanations. That solved my issue. Have a nice day! – oursay Feb 20 '14 at 11:52

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.