0

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:

enter image description here

(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:

enter image description here

(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}

output

enter image description here

enter image description here

  • well titlesec is not fully supported by hyperref (see the hyperref documentation). If you want to change only the fontsizes better use something else. Perhaps a solution is possible with titlesec, but such a solution can only be found if you provide a small but complete example demonstrating the issue, that can be used for testing and debugging. – Ulrike Fischer Oct 20 '20 at 09:21
  • Thanks for the answer! I actually didn't know hyperref was responsible for the metadata contents. Added a minimal complete example now. – Atai Ambus Oct 20 '20 at 09:44
  • Note that with very few exceptions hyperref should be loaded as the last package as it has to change/adapt to many other packages that might be in your preamble. – daleif Oct 20 '20 at 10:02
  • 1
    as @daleif wrote: in this case it is simply a problem of package loading order. – Ulrike Fischer Oct 20 '20 at 12:19

1 Answers1

-1

With a few exceptions hyperref should be loaded as the last package at it can then adjust it self according to the packages being loaded.

In the MWE given, if hyperref is moved after titlesec things seems to work as expected

daleif
  • 54,450
  • 1
    This came up because I was using LyX to write most of my documents, rather than pure LaTeX, and it puts all the package declarations it handles internally (including hyperref) before all the stuff you add manually in the preamble. So I'd like to note here that if you only want the contents' metadata and you use LyX, it's possible to disable hyperref in LyX's UI and add it in the preamble manually to fix it, but if you use any hyperlinks in the document LyX will add it anyway even if it's set disabled, and then the only option, in this specific issue at least, is to use sectsty. – Atai Ambus Oct 21 '20 at 08:19