我编写了一个简单的(自动化)报告,其中包含许多图形\includegraphics
。现在我想为每个图形生成一个目录链接,我可以单击该链接,因为包hyperref
。所以我写了
\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\newpage
\section{Start}
\begin{center}
\includegraphics{mwe/example-image-a.pdf}
\end{center}
\addcontentsline{toc}{subsection}{A}
\begin{center}
\includegraphics{mwe/example-image-a.pdf}
\end{center}
\addcontentsline{toc}{subsection}{A}
\begin{center}
\includegraphics{mwe/example-image-a.pdf}
\end{center}
\addcontentsline{toc}{subsection}{A}
\begin{center}
\includegraphics{mwe/example-image-b.pdf}
\end{center}
\addcontentsline{toc}{subsection}{B}
\begin{center}
\includegraphics{mwe/example-image-a.pdf}
\end{center}
\addcontentsline{toc}{subsection}{A}
\end{document}
(不确定 MWE 是如何工作的 :/)。但是,在 PDF 中生成的目录中,TOC 中的链接将我带到错误的页面,没有显示正确的图形。在示例中,单击 TOC 条目“B”不会让我转到图形“B”。
有没有办法获得我的图像的正确引用?
答案1
您必须使用 设置锚点\phantomsection
。并且我将使用minipage
或\parbox
来确保\phantomsection
和\includegraphics
都在同一页面上:
\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\newpage
\section{Start}
\begin{center}
\parbox{\linewidth}{
\centering
\phantomsection
\includegraphics{mwe/example-image-a.pdf}
\addcontentsline{toc}{subsection}{A}
}
\end{center}
\begin{center}
\parbox{\linewidth}{
\centering
\phantomsection
\includegraphics{mwe/example-image-a.pdf}
\addcontentsline{toc}{subsection}{A}
}
\end{center}
\begin{center}
\parbox{\linewidth}{
\centering
\phantomsection
\includegraphics{mwe/example-image-a.pdf}
\addcontentsline{toc}{subsection}{A}
}
\end{center}
\begin{center}
\parbox{\linewidth}{
\centering\phantomsection
\includegraphics{mwe/example-image-b.pdf}
\addcontentsline{toc}{subsection}{B}
}
\end{center}
\begin{center}
\parbox{\linewidth}{
\centering
\phantomsection
\includegraphics{mwe/example-image-a.pdf}
\addcontentsline{toc}{subsection}{A}
}
\end{center}
\end{document}