【问题标题】:Latex Table of Contents Links to Wrong Section乳胶目录链接到错误的部分
【发布时间】:2010-10-21 09:32:42
【问题描述】:

我有一个部分,后面是一个目录,如下所示:

\section{Section1}
ABC.

\addcontentsline{toc}{section}{Table of Contents}
\tableofcontents
\newpage
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage

\section{Section2}
DEF.
\section{Section3}
GHI.

我的问题是目录中的“目录”和“图表列表”条目(在生成的 pdf 中)链接到文件中的错误位置。它们都链接到第 1 页的第一部分。表中的条目是正确的(TOC 表示第 2 页,LOF 表示第 3 页),但链接指向错误的位置。

【问题讨论】:

  • 可以,可以添加序言等,方便其他人编译。

标签: latex pdflatex texmaker


【解决方案1】:

您需要使用\phantomsection 命令:

\section{Section1}
ABC.
\phantomsection
\addcontentsline{toc}{section}{Table of Contents}
\tableofcontents
\newpage
\phantomsection
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage

\section{Section2}
DEF.
\section{Section3}
GHI.

the hyperref manual

【讨论】:

  • 这只适用于目录和图表列表不超过一页的情况。否则,链接将指向列表的最后一页。
  • 我建议了一个不同的解决方案,无论哪种方式都可以工作。
  • 我必须在序言中添加\providecommand\phantomsection{}
  • 我可以确认,正如@Noah 所说,即使列表跨越多个页面,引用仍然可以按预期工作。
【解决方案2】:

如果您是为参考书目、表格列表或图形列表执行此操作,

\usepackage[nottoc]{tocbibind}

应该修复它,没有错误页面的问题。否则,我还没有找到比使用 \addcontentsline 的 \phantomsection 更好的解决方案。

【讨论】:

    【解决方案3】:

    这种行为是由于\tableofcontents 在写入内容之前插入了分页符。因此,您的 PDF 书签将指向之前的页面。根据您的文档类,您可以手动插入许多\newpage 命令以防止\tableofcontents 添加另一个命令。一两个就足够了。

    我知道,这是一个 hacky 解决方案,并且可能存在解决问题的包,但这就是我解决问题的方法。

    【讨论】:

    • 这不起作用,我添加了 1-3 个新页面,它仍然链接到上一节的开头。我编译了两次。
    猜你喜欢
    • 2014-11-04
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多