Figuras e tabelas no ToC dentro da seção

Figuras e tabelas no ToC dentro da seção

Tenho que cumprir um requisito de layout, onde o ToC inclui uma lista de figuras e uma lista de tabelas (tudo bem), mas adicionalmente nos marcadores do pdf cada figura e tabela devem ser indicadas na seção onde aparecem. Tome o seguinte 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}

Ele gera esse ToC, que é exatamente o que eu preciso:

insira a descrição da imagem aqui

Mas também gera estes marcadores de PDF:

insira a descrição da imagem aqui

Mas preciso que os marcadores do PDF tenham esta aparência (desculpe por usar o estilo Code):

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

Alguma ideia?

Responder1

A maneira mais fácil que consigo imaginar é conectar \captione adicionar o marcador com um rótulo de marcador exclusivo (gerado pelo número total de figuras ou tabelas)

Para obter os números totais, use o pacote (bem, meu ;-)) xassocnte associe a etapa dos contadores relevantes a eles.

Isso \pdfbookmark[2]{text}{label:name}adicionará a figura ou entrada da tabela como nível de subseção à seção atual.

Tenha cuidado ao usar \texorpdfstring{tex content}{pdf content}conteúdo específico da legenda, ou seja\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}

insira a descrição da imagem aqui

Atualizar

Isto não utiliza xassoccntsenão uma simples verificação \@captypee então aumenta o \total...contador relevante.

Ele usa \currentpdfbookmarkwhich cuida do nível da seção.

\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}

Próxima atualização: com figuras etc.

\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}

insira a descrição da imagem aqui

informação relacionada