# No section numbers, but still have PDF bookmarks with hyperref

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?

-
I know it sounds trivial, but it is always best to compose a MWE that illustrates the problem including the \documentclass and the appropriate packages, so that those trying to help don't have to recreate it. – Peter Grill Nov 4 '11 at 22:21
With a KOMA class like scrartcl one would use \addsec{title} instead of \section* in this case. – clemens Nov 18 '12 at 14:44
– cyberSingularity Nov 24 '12 at 16:27

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.

-
Would also be possible to redefine \@seccntformat locally to intermix numbered and unnumbered sections? This way the bookmarks are handled correctly in both. The only drawback, or required fix, is an addition to the table of contents using this method. – Werner Nov 4 '11 at 22:43
In case numbered and unnumbered sections are requested, the only way is to go with manual \bookmark, maybe redefining \section*. For the table of contents in case of all unnumbered sections, it's sufficient to redefine also \numberline to do nothing. Actually, it seems that Thorsten's solution is better. :) – egreg Nov 4 '11 at 22:48
Ah, \numberline yes. – Werner Nov 4 '11 at 22:49
Thank you, @egreg . Your solution worked but now I realize that I want the sections to be numbered, but not the subsections. Your solution removes all the sectioning commands numbers. I suppose my initial question wasn't entirely clear. – Jeremy Nov 5 '11 at 4:40

hyperref provides bookmarking functionality by means of

\pdfbookmark[<level>]{<text>}{<name>}


or

\currentpdfbookmark{<text>}{<name>}


in addition to others (see the hyperref documentation). Here is a minimal example:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\begin{document}
\section*{First section} \pdfbookmark{First section}{sec:first} \lipsum[1]
\section*{Second section} \pdfbookmark{Second section}{sec:second} \lipsum[2]
\section*{Third section} \pdfbookmark{Third section}{sec:third} \lipsum[3]
\section*{Last section} \pdfbookmark{Last section}{sec:fourth} \lipsum[4]
\end{document}


It would be possible to make this form part of the section command \section.

If you're only after bookmarks, and not so much concerned with internal document hyper references, use the bookmark package instead.

-

It is also possible to turn off heading numbering completely. Since you didn't explicitly say that you only want unnumbered sections, this might be an alternative.

\documentclass[11pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{blindtext}
\usepackage{hyperref}

\setcounter{secnumdepth}{0}

\begin{document}
\blinddocument
\end{document}


This way you can use the known \section command. Again, note that this would turn off numbering of all heading levels.

-
\setcounter{secnumdepth}{1} will number sections but not subsections, which is exactly what @Jeremy wanted, right? – Clara Dec 5 '13 at 16:25
@Clara: According to his last comment, it is. – Thorsten Donig Dec 5 '13 at 17:08

I've provided a way to make LaTeX essentially treat unnumbered sections in the same way as numbered sections (but pretend that they are really deep so that LaTeX won't number them), hopefully without breaking other things. This is same approach used in classes like amsart.

This means that one can have numbered and unnumbered sections in the same document, and all will appear in the table of contents and bookmarks as usual (the latter if hyperref is loaded, optional), with hyperlinks pointing to the right places, without any effort except loading the package! See the comments in the code below for more details. Note that this doesn't really need to be in a package, I just thought it might be more convenient.

However, note that the table of contents gets an entry in the table of contents, which may not be desirable! My example below illustrates how to suppress that also.

% save this as fix-unnumbered-sections.sty
\ProvidesPackage{fix-unnumbered-sections}

% This package is available at http://tex.stackexchange.com/q/33696/
% It patches the standard classes so that they treat unnumbered and numbered sections equally! (At least, I've tested it with the article class.)
% As a result, even the unnumbered sections gets entries in the TOC and, when hyperref is loaded, they also get bookmarks as per the default hyperref setting for bookmarks.
% Unnumbered sections can also have short titles for TOC and bookmark purposes, just like numbered sections.
%
% It works by pretending the unnumbered sections are deeper than \c@secnumdepth (in fact, just by assuming that they are 1000 (\@m) levels deep).
% I believe there are no side effects to this...

% We just pretend that \@ssect, which LaTeX uses to treat unnumbered [sub*]sections differently to (maybe) numbered ones (if they are no deeper than \c@secnumdepth levels), doesn't exist.
% Instead, we always use \@sect, which LaTeX uses for numbered sections, and sections which would otherwise be numbered if they weren't deeper than \c@secnumdepth levels.

\RequirePackage{etoolbox}
\patchcmd{\@startsection}{\@ssect{#3}{#4}{#5}{#6}}{\@dblarg{\@sect{#1}{\@m}{#3}{#4}{#5}{#6}}}{}{\PackageError{fix-unnumbered-sections}{Unable to patch \string\@startsection; are you using a non-standard document class?}\@ehd}


Here is a test file to explore the behaviour (needs two runs):

\documentclass[a4paper]{article}
\usepackage[bookmarksopen=true,bookmarksnumbered=true]{hyperref}
\usepackage{fix-unnumbered-sections}
\usepackage{lipsum}

\begin{document}
\tableofcontents\egroup

\section[First section]{This section is numbered}
\lipsum[1]
\subsection*[Unnumbered subsection]{This subsection is not numbered}
\lipsum[2]
\subsection[Numbered subsection]{But this one is}
\lipsum[3]
\newpage
\section*{This section is not numbered}
\lipsum[4]
\subsection*{And neither are its descendents}
\lipsum[5]
\end{document}


-

Here is a very short solution that does not require any changes to the preamble, provided you are loading hyperref:

\section*{Acknowledgements}% The * makes this section unnumbered.
\addcontentsline{toc}{section}{Acknowledgements}% This command makes the unnumbered section also appear in the pdf bookmarks.


Note: you do not need to call a table of contents in the beginning of the file for this to work.

-