2

I'm preparing a document (revtex4-1 class) with figures. I'd like to have bookmark for each figure in the PDF, so I use hyperref with the following command that inserts figures:

\newcommand{\AddFigureLabelContentCaption}[3]{{
\clearpage
\begin{figure}[t]
\currentpdfbookmark{Figure \arabic{figure}}{name:#1}
{#2}
\caption{#3}
\label{#1}
%\currentpdfbookmark{Figure \thefigure~[++]}{name:#1}
\end{figure}
}}

Everything is OK, but figure numbers start from zero. When I move the \currentpdfbookmark command after the label command, figure numbers in PDF bookmarks are OK. But clicking on the bookmark sends me right after the figure, which is not good.

Is it possible to output not the figure counter, but figure+1? I do not want to mess the figure counter, I just want to output a figure+1.

  • 1
    You can use: Figure \the\numexpr\arabic{figure}+1\relax or you can load the package hypcap – Marco Daniel Jun 6 '13 at 10:50
4

\thefigure can print a complex figure number and is not available for calculations in general (e.g. 1.4, (a), ...). A trick is to update the figure counter and reset it afterwards:

\stepcounter{figure}%
\currentpdfbookmark{Figure \thefigure}{name:#1}%
\addtocounter{figure}{-1}%

Package bookmark

  • The destination that is generated by \caption can be used for the bookmark, if package bookmark is used. Internally hyperref stores this in macro \@currentHref. (Currently package bookmark does not provide the feature of extracting the destination name from a label.)
  • Also I would put the figure bookmarks a level deeper than the current level without changing the current level afterwards.
  • Package caption (or hypcap) puts the anchor at the top of the figure instead to the location of \caption that usually goes below the actual figure.

Example:

\documentclass{article}
\usepackage{hyperref}
\usepackage{caption}
\usepackage{bookmark}
\bookmarksetup{
  numbered,
  open,
}
\begin{document}
\section{Hello World}
\begin{figure}
\centering
\fbox{\phantom{\rule{50mm}{10mm}}}
\caption{My caption}
\label{fig:my}
\bookmark[   
  rellevel=1,
  keeplevel=false,
  dest=\csname @currentHref\endcsname,
]{Figure \thefigure: My caption}
\end{figure}
\end{document}

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.