1

Following the guideline in section 3.9. Creating new levels and changing the class of the titlesec manual, I'm trying to create a new sectioning command \sectionsub under \section, to achieve what was asked in this previous question. My current code is given below.

However, I'm facing two issues:

  1. The numbering for subsection and subsubsection disappears.
  2. There is a warning bookmark level for unknown sectionsub defaults to 0.

Regarding 1), of course \setcounter{secnumdepth}{4} would work here, but the problem is that I'm not sure if 4 is the appropriate value. Regarding 2), \let\toclevel@sectionsub\toclevel@section works in the MWE given below, but for unknown reason, this does not work in the complete version of my document class (I tried to narrow down the problem for like an hour but it turns out to be fruitless).

How should I properly resolve these two issues?

\documentclass{book}

\usepackage[explicit]{titlesec} \usepackage{titletoc} \usepackage{hyperref} \usepackage{bookmark}

%% \sectionsub \titleclass{\sectionsub}{straight}[\section] \newcounter{sectionsub} \renewcommand{\thesectionsub}{\Alph{sectionsub}}

\titleformat{\sectionsub} {\large\scshape} {\thesectionsub} {1em} {#1} \titleformat{name=\sectionsub,numberless} {\large\scshape} {} {1em} {#1} \titlespacing{\sectionsub}{0pt}{.8\baselineskip}{.5\baselineskip}

\titlecontents{sectionsub} [4em] {\normalfont} {\contentslabel{1.75em}} {\hspace{-1.75em}} {\titlerule[1em]{.}\contentspage}

\begin{document}

\tableofcontents

\section{Test section} \sectionsub{Test sectionsub} \subsection{Test subsection} \subsubsection{Test subsubsection}

\end{document}

enter image description here

Jinwen
  • 8,518

1 Answers1

2

(1) Use \setcounter{secnumdepth}{4} to get numbered sub sections and sub sub sections in the book class. (Plus \setcounter{tocdepth}{4} to make them appear in the ToC)

(2) Load hyperref as the last package.

(3) with

\makeatletter
\def\toclevel@section{1}
\def\toclevel@sectionsub{2}
\def\toclevel@subsection{3}
\def\toclevel@subsubsection{4}
\makeatother

the warning disappears and the \sectionsub is in the right place (after section and before subsection).

a

Simon Dispa
  • 39,141
  • Thank you! One quick question: if I'm using class article instead of book, should I change the 1 in \def\toclevel@sectionsub{1} to 0 to make it the same level with section? – Jinwen Jul 04 '22 at 20:22
  • Also, regarding your 2), it seems from https://tex.stackexchange.com/a/113007 that the order of hyperref and bookmark doesn't really matter, one just needs to be careful about option clash. – Jinwen Jul 04 '22 at 20:23
  • 1
    (1) I do not see any difference of the output between book and article. (2) sometimes one forgets and adds new packages after hyperref. (there are exceptions) It works better for me to follow a general rule. Thank you for your feedback! – Simon Dispa Jul 04 '22 at 20:33