Assuming that you're using hyperref
already*, the documentation states:
Usually hyperref
automatically adds bookmarks for \section
and similar macros. But they can also set manually.
The manual setting is performed using
\pdfbookmark[<level>]{<text>}{<name>}
where \part
is level -1
, \chapter
is level 0
, \section
is level 1
, ... It places <text>
in the bookmarks and can be referenced internally (via a hyperlink) as <name>
. Or, if you want to place it at a level relative to the current one, use
\currentpdfbookmark{<text>}{<name>}
\subpdfbookmark{<text>}{<name>}
\belowpdfbookmark{<text>}{<name>}
where <text>
and <name>
have similar meanings as before.
In the following MWE, hyperref
creates sectional bookmarks for every unstarred heading up to secnumdepth
and only the numbered, unstarred versions show up in the ToC. The starred versions, removed from the ToC by default, are included using some variation of \...pdfbookmark
:
\documentclass{book}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\usepackage{bookmark}% http://ctan.org/pkg/bookmark
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\tableofcontents
\part{FIRST PART}
\chapter{First chapter} \lipsum[1]
\section{First section} \lipsum[2]
\section*{Second section} \currentpdfbookmark{Second section}{ch:1:sec:2} \lipsum[3]
\section{Third section} \lipsum[4]
\subsection{First subsection} \lipsum[5]
\subpdfbookmark{First subsubsection}{ch:1:sec:3:ssec:1:sssec:1}\subsubsection{First subsubsection} \lipsum[6]
\currentpdfbookmark{Second subsubsection}{ch:1:sec:3:ssec:1:sssec:2} \subsubsection*{Second subsubsection} \lipsum[7]
\subsection{Second subsection} \lipsum[8]
\currentpdfbookmark{Third subsection}{ch:1:sec:3:ssec:3} \subsection*{Third subsection} \lipsum[9]
\pdfbookmark[2]{Fourth subsection}{ch:1:sec:3:ssec:4}\subsection*{Fourth subsection} \lipsum[10]
\subsection{Fifth subsection} \lipsum[11]
\chapter{Second chapter} \lipsum[12]
\end{document}
For the inclusion of sectional numbers in the PDF bookmark panel, use the bookmarksnumbered
option of hyperref
:
\usepackage[bookmarksnumbered]{hyperref}% http://ctan.org/pkg/hyperref
The above MWE will then produce:
* If not, the bookmark
package provides similar, stand-alone functionality for inclusion of PDF bookmarks in your document. In fact, hyperref
suggests using it as improved bookmark organization.
Here are two ways of doing things, with the help of the changcntr
package.
First, if you do not want to display 0
for non-existent subsections — i.e. if there is no subsection at one point, display only the section number+the equation number:
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{chngcntr}
\usepackage{etoolbox}
\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\renewcommand\theequation{\ifnumgreater{\value{subsection}}{0}{\thesubsection.}{\thesection.}\arabic{equation}}%
\begin{document}
\section{A First Section}
\begin{equation}
a = b
\end{equation}
\begin{equation}
a + c = b + c
\end{equation}
\begin{equation}
a × c = b × c
\end{equation}
\section{A Second Section}
\begin{equation}
a = b
\end{equation}
\begin{equation}
a + c = b + c
\end{equation}
\section{A Third Section}
An extra equation :
\begin{equation}\
\ln a = \ln b
\end{equation}
\subsection{First subsection}
\begin{equation}
a = b
\end{equation}
\begin{equation}
a + c = b + c
\end{equation}
\subsection{Second subsection}
\begin{equation}
a = b
\end{equation}
\begin{equation}
a + c = b + c
\end{equation}
\end{document}
If you want the 0
to be displayed, remove from the preamble \renewcommand\theequation{…}
and \usepackage{etoolbox}
, and replace counterwithin*{equation}{subsection}
with the non-starred version.
Best Answer
Package
hyperref
needs the counter values to generate unique anchor names. But there are counter values that are not unique. For example, you have several sections with number1
.Because of this,
hyperref
has introduced\theH<counter>
and prefers it over\the<counter>
for use in anchor names.\the<counter>
might contain weird or duplicate values. As long as\theH<counter>
expands to a simple unique string,hyperref
is happy.The following example provides unique definitions for
\theHsection
: