1

I had to to define a \subsubsubsection for a technical document (I know it is highly criticised). I believe I inspired myself from this alternative answer to How to add an extra level of sections with headings below \subsubsection at that time (I couldn't use the package titlesec, but I can't remember the reason).

However, the hierarchy in the PDF bookmarks is messed up: subsubsubsection is shown as level 1 instead of 4, even though I tell \@startsection it's level 4 in the definition of \subsubsubsection. I wrongly expected this to handle PDF bookmarks implicitly as well.

How do I tell the package which is handling the PDF bookmarks (I guess hyperref) that the \subsubsubsection is level 4? Or alternatively as a suboptimal workaround, how do I tell \subsubsubsection not to show up in the PDF bookmarks at all (remember, setting bookmarksdepth<4 is not working, since it is ignoring that it is level 4).

enter image description here

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{hyperref}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{4}
\hypersetup{bookmarksdepth=4}

\makeatletter
\newcounter{subsubsubsection}[subsubsection]
\renewcommand{\thesubsubsubsection}{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand{\theparagraph}{\thesubsubsubsection.\arabic{paragraph}}

\newcommand{\subsubsubsection}{\@startsection{subsubsubsection}{4}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\it\bfseries}}
\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}}

\newcommand*{\l@subsubsubsection}{\@dottedtocline{4}{11em}{5em}}  
\renewcommand*{\l@paragraph}{\@dottedtocline{5}{12em}{6em}}
\renewcommand*{\l@subparagraph}{\@dottedtocline{6}{14em}{7em}}

\newcommand{\subsubsubsectionmark}[1]{}
\makeatother

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsubsubsection{SubsubsubSection}


\end{document}
  • I don't know if it suits your needs, but maybe the bookmark package (that fixes some strange behaviors of hyperref) can be useful – Moriambar Oct 21 '15 at 14:49
  • latex provides section levels below subsubsection by default, why insert a new one in the middle of the sequence? Do you really need all 6 levels? – David Carlisle Oct 21 '15 at 14:49
2

If this is really needed, use bookmark package, say depth=3 as option (i.e. only down to subsubsection) and (more important!!!):

You've to specify the level in which the new subsubsubsection has to be hooked to:

\newcommand{\toclevel@subsubsubsection}{4}

This way you inform hyperref (and the bookmark) package, that subsubsubsection counters are on level 4.

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{hyperref}
\usepackage[depth=3]{bookmark}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{4}
%\hypersetup{bookmarksdepth=4}



\makeatletter

\newcommand{\toclevel@subsubsubsection}{4}
\newcounter{subsubsubsection}[subsubsection]

\renewcommand{\thesubsubsubsection}{\thesubsubsection.\arabic{subsubsubsection}}


\renewcommand{\theparagraph}{\thesubsubsubsection.\arabic{paragraph}}

\newcommand{\subsubsubsection}{\@startsection{subsubsubsection}{4}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\it\bfseries}}
\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}}

\newcommand*{\l@subsubsubsection}{\@dottedtocline{4}{11em}{5em}}  
\renewcommand*{\l@paragraph}{\@dottedtocline{5}{12em}{6em}}
\renewcommand*{\l@subparagraph}{\@dottedtocline{6}{14em}{7em}}

\newcommand{\subsubsubsectionmark}[1]{}
\makeatother

\begin{document}

\tableofcontents

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\phantomsection
\subsubsubsection{SubsubsubSection}


\end{document}

enter image description here

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.