0

I'm using titlesec to format subsections so that they are not numbered (as opposed to using the usual starred variant \subsection*) and using hyperref to get bookmarks with section numbers in the resulting PDF file. The bookmarksnumbered option to hyperref does not know the titlesec formatting, so the bookmarks for subsections are coming out numbered, though…

Question: is there a way to get titlesec and hyperref to play nice to each other so that these numbers are omitted from the PDF bookmarks?

This little example

\documentclass{article}
\usepackage[
        bookmarksnumbered,
        bookmarksdepth=2
        ]{hyperref}
\usepackage{titlesec}

\titleformat{\subsection}
        {\Large} 
        {} 
        {0pt} 
        {} 
        {} 

\begin{document}
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second Section}
\subsection{First subsection}
\subsection{Second subsection}
\end{document}

gets you this:

Resulting TOC in the PDF

2
  • 1
    My approach has generally been to use the starred form and then use hyperref's pdfbookmark. Is there a particular reason you don't want the starred form?
    – Teepeemm
    Aug 10 '20 at 0:57
  • @Teepeemm, mostly because I really prefer to be able to change the output without having to change the markup. Aug 10 '20 at 14:32
1

your method to get unnumbered subsection is imho wrong: you still get numbers in the table of contents which looks simply odd:

\documentclass{article}
\usepackage[
        bookmarksnumbered,
        bookmarksdepth=2
        ]{hyperref}
\usepackage{titlesec}

\titleformat{\subsection}
        {\Large}
        {}
        {0pt}
        {}
        {}

\begin{document}
\tableofcontents
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second Section}
\subsection{First subsection}
\subsection{Second subsection}
\end{document}

enter image description here

So why don't you simply change secnumdepth? Then everything will be numbered in the same way:

\documentclass{article}
\usepackage[
        bookmarksnumbered,
        bookmarksdepth=2
        ]{hyperref}
\setcounter{secnumdepth}{1}
\begin{document}
\tableofcontents
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second Section}
\subsection{First subsection}
\subsection{Second subsection}
\end{document}

enter image description here

2
  • Well, my tocdepth is such that subsections do not show up in the toc ;-) Aug 10 '20 at 14:25
  • your bookmark-tocdepth is not -- that's why you are asking the question don't you? Aug 10 '20 at 14:27

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.