TransWikia.com

Hyperref bookmarks for unnumbered sections

TeX - LaTeX Asked by Mariano Suárez-Álvarez on February 4, 2021

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

One Answer

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

Answered by Ulrike Fischer on February 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP