目录中的图表

目录中的图表

我必须满足布局要求,其中目录包含一个图表列表和一个表格列表(没问题),但此外,在 pdf 书签中,每个图表和表格都应在其出现的部分中标出。以以下 MWE 为例:

\documentclass[12pt]{article}
\usepackage{todonotes}
\usepackage{graphicx}
\usepackage{float}
\restylefloat{table}
\restylefloat{figure}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[a4paper, margin=3cm, top=3cm, bottom=3cm]{geometry}
\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\hypersetup{
linktocpage=true,
colorlinks=true,
linkcolor=blue,
filecolor=blue,      
urlcolor=blue,
bookmarksopen=true
}
\bookmarksetup{numbered}

\title{\begin{center}
My Title
\end{center}
} 
\date{}
\author{}

\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

\setcounter{page}{2}

\newpage
\pdfbookmark[0]{Contents}{Contents}
\tableofcontents
\listoffigures
\listoftables

\newpage
\section{My first section}

Bla, bla bla.

\begin{figure}[H]
\caption{My first Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My first Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end{tabular}
\end{table}

\newpage
\section{My second section}

More bla, bla.

\begin{figure}[H]
\caption{My second Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My second Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\end{document}

它生成了这个 ToC,这正是我所需要的:

在此处输入图片描述

但它也会生成这些 pdf 书签:

在此处输入图片描述

但我需要 pdf 书签看起来像这样(抱歉使用了代码风格):

Contents
|- 1 My first Section
   |- My first figure
   |- My first table 
|- 2 My second Section
   |- My second figure
   |- My second table

有任何想法吗?

答案1

我能想到的最简单的方法是使用\caption唯一的书签标签(由图形或表格的总数生成)来添加书签

要获得总数,请使用(嗯,我的;-))包xassocnt并将相关计数器与它们关联起来。

将会\pdfbookmark[2]{text}{label:name}将图形或表格条目作为子节级别添加到当前节。

请谨慎使用\texorpdfstring{tex content}{pdf content}标题的具体内容,即\caption{\texorpdfstring{$E=mc^2}{E=mc\textsuperscript{2}}}

\documentclass[12pt]{article}
\usepackage{todonotes}
\usepackage{graphicx}
\usepackage{xassoccnt}

\newcounter{totalfigure}
\newcounter{totaltable}

\DeclareAssociatedCounters{figure}{totalfigure}
\DeclareAssociatedCounters{table}{totaltable}


\usepackage{float}
\restylefloat{table}
\restylefloat{figure}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{caption}




\makeatletter
\AtBeginDocument{%
\let\caption@@caption\caption
\RenewDocumentCommand{\caption}{som}{%
  \IfBooleanTF{#1}{%
    \caption@@caption{#3}%
  }{%
    \IfValueTF{#2}{%
      \caption@@caption[#2]{#3}%
      \pdfbookmark[2]{#2}{\@captype:\number\value{total\@cap@type}}%
    }{%
      \phantomsection
      \caption@@caption{#3}%
      \pdfbookmark[2]{#3}{\@captype:\number\value{total\@captype}}%
    }%
  }%
}
}


\usepackage[a4paper, margin=3cm, top=3cm, bottom=3cm]{geometry}
\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\hypersetup{
  linktocpage=true,
  colorlinks=true,
  linkcolor=blue,
  filecolor=blue,      
  urlcolor=blue,
  bookmarksopen=true
}

%\captionsetup[figure]{format=bookmarksfig}
%\captionsetup[table]{format=bookmarkstab}


\bookmarksetup{numbered}

\title{\begin{center}
    My Title
\end{center}
} 
\date{}
\author{}

\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

\setcounter{page}{2}

\newpage
\pdfbookmark[0]{Contents}{Contents}
\tableofcontents
\listoffigures
\listoftables

\newpage
\section{My first section}

Bla, bla bla.

\begin{figure}[H]
\caption{My first Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My first Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end{tabular}
\end{table}

\newpage
\section{My second section}

More bla, bla.

\begin{figure}[H]
\caption{My second Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My second Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\end{document}

在此处输入图片描述

更新

这不起作用xassoccnt,但可以进行简单的检查\@captype并增加相关\total...计数器。

它使用\currentpdfbookmark它来处理部分级别。

\documentclass[12pt]{article}
\usepackage{todonotes}
\usepackage{graphicx}


\newcounter{totalfigure}
\newcounter{totaltable}

%\usepackage{xassoccnt}
%\DeclareAssociatedCounters{figure}{totalfigure}
%\DeclareAssociatedCounters{table}{totaltable}


\usepackage{float}
\restylefloat{table}
\restylefloat{figure}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{caption}


\usepackage{xparse}


\makeatletter
\AtBeginDocument{%
  \let\caption@@caption\caption


\RenewDocumentCommand{\caption}{som}{%
  %checking which caption type is here and stepping the relevant total counter
  \def\temp@@a{figure}
  \def\temp@@b{table}
  \ifx\@captype\temp@@a 
  \stepcounter{total\@captype}%
  \fi
  \ifx\@captype\temp@@b 
  \stepcounter{total\@captype}%
  \fi
  \IfBooleanTF{#1}{%
    \caption@@caption{#3}%
  }{%
    \IfValueTF{#2}{%
      \phantomsection
      \caption@@caption[#2]{#3}%
      \currentpdfbookmark{#2}{\@captype:\number\value{total\@cap@type}}%
    }{%
      \phantomsection
      \caption@@caption{#3}%
      \currentpdfbookmark{#3}{\@captype:\number\value{total\@captype}}%
    }%
  }%
}
}
\makeatother


\usepackage[a4paper, margin=3cm, top=3cm, bottom=3cm]{geometry}
\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\hypersetup{
  linktocpage=true,
  colorlinks=true,
  linkcolor=blue,
  filecolor=blue,      
  urlcolor=blue,
  bookmarksopen=true
}



\bookmarksetup{numbered}

\title{%
  \begin{center}
    My Title
  \end{center}
} 
\date{}
\author{}

\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

\setcounter{page}{2}%

\newpage
\pdfbookmark[0]{Contents}{Contents}
\tableofcontents
\listoffigures
\listoftables

\newpage
\section{My first section}

Bla, bla bla.

\begin{figure}[H]
\caption{My first Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My first Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end{tabular}
\end{table}

\newpage
\section{My second section}

More bla, bla.

\begin{figure}[H]
\caption{My second Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My second Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\subsection{Foo subsection}

\begin{figure}[H]
\caption{My third Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My third Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}


\subsubsection{Foo subsubsection}


\begin{figure}[H]
\caption{My fourth Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My fourth Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\clearpage

\section{Yet another section}



\begin{figure}[H]
\caption{My sixth Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My sixth Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\subsection{Foo subsection}

\begin{figure}[H]
\caption{My seventh Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My seventh Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}


\subsubsection{Foo subsubsection}


\begin{figure}[H]
\caption{My eighth Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My eighth Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}


\end{document}

下次更新:包含图形等数字

\documentclass[12pt]{article}
\usepackage{todonotes}
\usepackage{graphicx}


\newcounter{totalfigure}
\newcounter{totaltable}

%\usepackage{xassoccnt}
%\DeclareAssociatedCounters{figure}{totalfigure}
%\DeclareAssociatedCounters{table}{totaltable}


\usepackage{float}
\restylefloat{table}
\restylefloat{figure}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{caption}


\usepackage{xparse}


\makeatletter
\AtBeginDocument{%
  \let\caption@@caption\caption

\newcommand{\generatebookmark}[1]{%
  \belowpdfbookmark{\csname \@captype name\endcsname\ \csname the\@captype\endcsname: #1}{\@captype:\number\value{total\@captype}}%
}


\RenewDocumentCommand{\caption}{som}{%
  %checking which caption type is here and stepping the relevant total counter
  \def\temp@@a{figure}
  \def\temp@@b{table}
  \ifx\@captype\temp@@a 
  \stepcounter{total\@captype}%
  \fi
  \ifx\@captype\temp@@b 
  \stepcounter{total\@captype}%
  \fi
  \IfBooleanTF{#1}{%
    \caption@@caption{#3}%
  }{%
    \IfValueTF{#2}{%
      \phantomsection
      \caption@@caption[#2]{#3}%
      \generatebookmark{#2}%
    }{%
      \phantomsection
      \caption@@caption{#3}%
      \generatebookmark{#3}%
    }%
  }%
}
}
\makeatother


\usepackage[a4paper, margin=3cm, top=3cm, bottom=3cm]{geometry}
\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\hypersetup{
  linktocpage=true,
  colorlinks=true,
  linkcolor=blue,
  filecolor=blue,      
  urlcolor=blue,
  bookmarksopen=true
}



\bookmarksetup{numbered}

\title{%
  \begin{center}
    My Title
  \end{center}
} 
\date{}
\author{}

\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

\setcounter{page}{2}%

\newpage
\pdfbookmark[0]{Contents}{Contents}
\tableofcontents
\listoffigures
\listoftables

\newpage
\section{My first section}

Bla, bla bla.

\begin{figure}[H]
\caption{My first Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My first Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end{tabular}
\end{table}

\newpage
\section{My second section}

More bla, bla.

\begin{figure}[H]
\caption{My second Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My second Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\subsection{Foo subsection}

\begin{figure}[H]
\caption{My third Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My third Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}


\subsubsection{Foo subsubsection}


\begin{figure}[H]
\caption{My fourth Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My fourth Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\clearpage

\section{Yet another section}



\begin{figure}[H]
\caption{My sixth Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My sixth Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}

\subsection{Foo subsection}

\begin{figure}[H]
\caption{My seventh Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My seventh Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}


\subsubsection{Foo subsubsection}


\begin{figure}[H]
\caption{My eighth Figure}
\missingfigure[figwidth=6cm]{}
\end{figure}

\begin{table}[H]
\caption{My eighth Table}
\begin{tabular}{ |c|c|c| } 
 \hline
 cell1 & cell2 & cell3 \\ 
 cell4 & cell5 & cell6 \\ 
 cell7 & cell8 & cell9 \\ 
 \hline
\end {tabular}
\end{table}


\end{document}

在此处输入图片描述

相关内容