目录中的超链接到 pdf 图像

目录中的超链接到 pdf 图像

我可以建立一个目录来引导我到每个章节,如下例所示:带超链接的目录.我的代码:

\documentclass{book}
\usepackage[left=1.5cm,right=1.5cm]{geometry}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}    
\usepackage[table]{xcolor}
\usepackage{booktabs,newtxtext,newtxmath,multirow}
\usepackage{ltablex}
\usepackage{sectsty}
\chapterfont{\color{darkblue2}}
\renewcommand{\thepage}{\textcolor{darkblue2}{\arabic{page}}}
\usepackage{hyperref}
\hypersetup{colorlinks=,linkcolor=darkblue2}
\pagecolor{white}
\usepackage{pdfpages,graphics}
\definecolor{lilita}    {RGB}{215,205,247}
\definecolor{darkblue2} {rgb}{0,0,0.7}
\pagestyle{plain}
\begin{document}
\includepdf[pages=2]{portadas}
\pagecolor{lilita}
{\makeatletter
 \let\@oldstarttoc\@starttoc
 \renewcommand{\@starttoc}{%
 \addcontentsline{toc}{chapter}{\protect\numberline{}\contentsname}
 \@oldstarttoc}
\tableofcontents
\makeatother}
\includepdf[pages=4]{portadas}
\include{i}
\includepdf[pages=5]{portadas}
\include{u}
\end{document}

在文件“i.tex”和“u.tex”中我放了

\phantomsection 
\addcontentsline{toc}{chapter}{I}

生成目录中的“入口”。超链接正确地将我带到每个章节开始的页面。每个章节的第一页都有一张我在其他地方生成的图像,包含在文件中:波塔达斯。我希望超链接能带我到这张图片,而不是每章的“第 2 页”。可以吗?

答案1

\addcontentsline下面的MWE演示了代码中命令的不同位置可以获得的不同输出。

在第一个示例中,命令被放置在 \includepdf并且目录中的超链接正确地指向包含pdf的页面。

在第二个示例中,\addcontentsline命令被放置在\includepdf命令以及目录中的超链接将引导至所包含的 pdf 之后的页面。

\documentclass{book}
\usepackage[left=1.5cm,right=1.5cm]{geometry}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}    

\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\clearpage 
\phantomsection 
\addcontentsline{toc}{chapter}{This takes me to the included pdf}
\includepdf[pages=4]{portadas}

%%%%%%%%%%% The following could also be in 'i.tex'%%%%%
Some text that represents the contents of i.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\includepdf[pages=5]{portadas}

%%%%%%%%%%% The following could also be in 'u.tex'%%%%%
\phantomsection 
\addcontentsline{toc}{chapter}{This takes me to the page after the inserted pdf image.}
Some text that represents the contents of u.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

相关内容