我想在图片列表下自动生成书签。下面的代码为每个图片添加了书签(这很好),但我无法在图片列表下自动生成相同的书签(无需手动输入下面代码中注释掉的代码)。任何帮助或建议都将不胜感激!
\documentclass{article}
\usepackage{caption}
\usepackage[bookmarksnumbered]{hyperref}
\hypersetup{colorlinks,
linkcolor=blue,
linktoc=page}
\usepackage{bookmark}
\usepackage{etoolbox}
\usepackage{tocloft}
%%% Generate bookmarks for all figures
\makeatletter
\pretocmd\endfigure{%
\bookmark[
rellevel=1,
keeplevel,
dest=\@currentHref,
]{Figure \thefigure: \@currentlabelname}%
}{}{\errmessage{Patching \noexpand\endfigure failed}}
\makeatother
% %%% Format list of tables and list of figures
\newlength{\mylen}
\renewcommand{\cfttabpresnum}{\tablename\space}
\renewcommand{\cfttabaftersnum}{}
\settowidth{\mylen}{\cfttabpresnum\cfttabaftersnum}
\addtolength{\cfttabnumwidth}{2cm}
\renewcommand{\cftfigpresnum}{\figurename\space}
\renewcommand{\cftfigaftersnum}{}
\settowidth{\mylen}{\cftfigpresnum\cftfigaftersnum}
\addtolength{\cftfignumwidth}{2cm}
\begin{document}
\phantomsection
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
%\bookmark[
% dest=Figure1,
% rellevel=1,
% keeplevel]{Figure 1: Figure caption text}
%\bookmark[
% dest=Figure2,
% rellevel=1,
% keeplevel]{Figure 2: Figure caption text 2}
\newpage
\section{The document}
\begin{figure}[ht]
\centering
\rule{6cm}{3cm}
\caption{Figure caption text}
%\hypertarget{Figure1}{}
\end{figure}
\newpage
\begin{figure}[ht]
\centering
\rule{6cm}{3cm}
\caption{Figure caption text 2}
%\hypertarget{Figure2}{}
\end{figure}
\end{document}
当前的:
目标:
答案1
请在此处查看相关问题:图表的自定义书签列表
最简单的方法是将相同的书签条目写入文件,以便在发出时(通过读取文件).lof
生成书签。\listoffigures
.lof
这可以通过使用(参见下面的代码)来实现\addtocontents{lof}{\protect{\bookmark{}...}
。
\documentclass{article}
\usepackage{caption}
\usepackage{etoolbox}
\usepackage{tocloft}
\usepackage[bookmarksnumbered,bookmarksopen=true]{hyperref}
\hypersetup{colorlinks,
linkcolor=blue,
linktoc=page}
\usepackage{bookmark}
%%% Generate bookmarks for all figures
\makeatletter
\pretocmd\endfigure{%
\addtocontents{lof}{\protect{%
\bookmark[
rellevel=1,
keeplevel,
dest=\@currentHref,
]{Figure \thefigure: \@currentlabelname}}}%
\bookmark[
rellevel=1,
keeplevel,
dest=\@currentHref,
]{Figure \thefigure: \@currentlabelname}%
}{}{\errmessage{Patching \noexpand\endfigure failed}}
\makeatother
% %%% Format list of tables and list of figures
\newlength{\mylen}
\renewcommand{\cfttabpresnum}{\tablename\space}
\renewcommand{\cfttabaftersnum}{}
\settowidth{\mylen}{\cfttabpresnum\cfttabaftersnum}
\addtolength{\cfttabnumwidth}{2cm}
\renewcommand{\cftfigpresnum}{\figurename\space}
\renewcommand{\cftfigaftersnum}{}
\settowidth{\mylen}{\cftfigpresnum\cftfigaftersnum}
\addtolength{\cftfignumwidth}{2cm}
\begin{document}
\phantomsection
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage
\section{The document}
\begin{figure}[ht]
\centering
\rule{6cm}{3cm}
\caption{Figure caption text}
\end{figure}
\newpage
\section{Different section}
\begin{figure}[ht]
\centering
\rule{6cm}{3cm}
\caption{Figure caption text 2}
\end{figure}
\end{document}