While writing this question I have found a workaround, using sectsty
instead of titlesec
. But since it's a workaround rather than a real solution, I'd like to know what was the issue and how I might go fixing it directly.
So I have a long, chronologically organized diary that uses sectioning pretty heavily. Thus I often use the table of contents that are generated in the PDF's metadata to navigate through the document. This is all nice and good, and on a normal compilation, Okular shows the following, as it should:
(And so on).
However, I don't want the sections to be numbered. I understand that \setcounter{secnumdepth}{-2}
can be used to remove numbering completely, and that does work. However, I would like to change the size of the section headings. From this answer I got the following code:
\usepackage{titlesec}
\titleformat*{\section}{\LARGE\bfseries}
\titleformat*{\subsection}{\Large\bfseries}
\titleformat*{\subsubsection}{\large\bfseries}
\titleformat*{\paragraph}{\large\bfseries}
\titleformat*{\subparagraph}{\large\bfseries}
And it works, but suddenly the contents turn into a complete mess:
(And so on).
Debugging showed that the problem exists only when both the lines \setcounter{secnumdepth}{-2}
and \usepackage{titlesec}
Exist. The table of contents in the document itself is intact, and everything that stays numbered also doesn't change in the contents.
As stated in the beginning, I ended up just switching to resizing the section headings with sectsty
, which fixed the problem. But I am curious - what caused the problem? Is there a way to use both \setcounter{secnumdepth}
and titlesec
without breaking the metadata contents?
Minimal Reproducible Example
code
\documentclass{article}
\usepackage{hyperref}
\setcounter{secnumdepth}{0}
\usepackage{titlesec}
\begin{document}
\part{Example Part}
\section{Examle Section}
\subsection{Example subsection}
\subsubsection{Example Paragraph}
\section{Example Second section}
\subsection{Example second subsection}
\part{Example Second Part}
\section{Example Second section}
\subsection{Example second subsection}
\end{document}
hyperref
should be loaded as the last package as it has to change/adapt to many other packages that might be in your preamble.