GeneralPDF Bookmarks for Figure and Table Entries

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Bergmann
Posts: 3
Joined: Wed Sep 12, 2012 9:59 am

PDF Bookmarks for Figure and Table Entries

Post by Bergmann »

I need to add bookmarks for all figure and table entries in my document. The bookmark should contain the name of the entry (figure and table) the number and the caption.

I found one way of doing this using the bookmark package, however this requires that I manually insert the bookmark after each figure/table, and copy the caption to the bookmark. Does anybody know a smarter way of doing this?

Thanks!

Here is a short version of my current code:

Code: Select all

\documentclass[twoside]{article}
\usepackage[linktocpage=true,bookmarksnumbered=true]{hyperref}                    
\usepackage{bookmark}

\begin{document}
\section{Figures}

\begin{figure}
\hypertarget{fig}{}
\includegraphics[width=\textwidth]{figure}
\caption{Caption text}
\end{figure}
\bookmark[rellevel=1,keeplevel,dest=fig]{Figure \thefigure{} Caption text}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

PDF Bookmarks for Figure and Table Entries

Post by cgnieder »

Hi Bergmann,

Welcome to the LaTeX community!

You could try using the caption package and redefine the caption text format to create the bookmarks:

Code: Select all

% needs two runs
\documentclass{article}
\usepackage{caption}
\usepackage{hyperref}
\DeclareCaptionTextFormat{bookmark}{\belowpdfbookmark{Figure \thefigure: #1}{\thefigure}#1}
\captionsetup{textformat=bookmark}

\begin{document}
\null\newpage% to see that the bookmark's working
\section{Figures}

\begin{figure}[ht]
 \centering
 \rule{6cm}{3cm}
 \caption{Caption text}
\end{figure}

\begin{figure}[ht]
 \centering
 \rule{6cm}{3cm}
 \caption{Another caption text}
\end{figure}

\end{document}
Regards
site moderator & package author
Bergmann
Posts: 3
Joined: Wed Sep 12, 2012 9:59 am

PDF Bookmarks for Figure and Table Entries

Post by Bergmann »

Thanks for the welcome to the Latex community and for the quick reply. This was exactly what I was looking for!

I added \DeclareCaptionTextFormat seperately for Figures and Tables and also had to add an extra \captionsetup for subfigures, such that my code now looks like this:

Code: Select all

\usepackage{hyperref}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{bookmark}
\DeclareCaptionTextFormat{bookmarkf}{\belowpdfbookmark{Figure \thefigure: #1}{\thefigure}#1}
\captionsetup[figure]{textformat=bookmarkf}
\DeclareCaptionTextFormat{bookmarkt}{\belowpdfbookmark{Table \thetable: #1}{\thetable}#1}
\captionsetup[table]{textformat=bookmarkt}
\captionsetup[sub]{textformat=simple}
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

PDF Bookmarks for Figure and Table Entries

Post by ssfjhh »

Hi cgnieder,

your code works very well, but when the figure caption is empty, it doesn't work, how can I do with this? Notice the empty \caption! :(

Code: Select all

\documentclass{article}
\usepackage{caption}
\usepackage{hyperref}
\DeclareCaptionTextFormat{bookmark}{\belowpdfbookmark{Figure \thefigure: #1}{\thefigure}#1}
\captionsetup{textformat=bookmark}

\begin{document}
\null\newpage% to see that the bookmark's working
\section{Figures}

\begin{figure}[ht]
 \centering
 \rule{6cm}{3cm}
 \caption{}
\end{figure}

\begin{figure}[ht]
 \centering
 \rule{6cm}{3cm}
My Englist is poor. If something I wrote confuses you, please let me know.
Bergmann
Posts: 3
Joined: Wed Sep 12, 2012 9:59 am

PDF Bookmarks for Figure and Table Entries

Post by Bergmann »

Dear all,

The solution for automatically including bookmarks for figures and tables have worked perfectly so far, but now I ran into a problem. When the numbers of the table and figure are the same and I include e.g Figure 1 before Table 1, the bookmark only works for Figure 1 whereas the bookmark for Table 1 points to Figure 1. Does anybody have a solution for this problem?

Thank you!

Code: Select all

\usepackage{cleveref}
\usepackage{bookmark}
\usepackage{caption}
\DeclareCaptionTextFormat{bookmarkt}{\belowpdfbookmark{Table \thetable: #1}{\thetable}#1}
\captionsetup[table]{textformat=bookmarkt}
\DeclareCaptionTextFormat{bookmarkf}{\belowpdfbookmark{Figure \thefigure: #1}{\thefigure}#1}
\captionsetup[figure]{textformat=bookmarkf}
MaMa
Posts: 1
Joined: Fri Mar 28, 2014 12:53 am

Re: PDF Bookmarks for Figure and Table Entries

Post by MaMa »

I love this function, but would prefer to use the short caption as the text in the bookmark. Does anyone know how to achieve this?

Thanks!
Post Reply