[Tex/LaTex] No section numbers, but still have PDF bookmarks with hyperref

bookmarkshyperref

I have a document that has many sections. I don't want section numbers to show up in the document, but I do want the sections to show up automagically as bookmarks in the PDF using the hyperref package.

I know I can use the \section* command to eliminate section numbers in the document, but this also removes the bookmark. Is there some sort of compromise?

Best Answer

You can just suppress the appearance of the section number:

\documentclass[a4paper]{article}
\usepackage{hyperref}
\usepackage{bookmark}
\makeatletter
\renewcommand\@seccntformat[1]{}
\makeatother

\begin{document}
\section{A}
a
\newpage
\section{B}
b
\end{document}

The macro \@seccntformat is responsible for printing the section number; by redefining it to "do nothing" the number is not printed, but hyperref is able to create the bookmark correctly.

The bookmark package is a good add-on, as it avoids some weaknesses of the original implementation of bookmark creation.

Related Question