【问题标题】:LaTeX hyperref link goes to wrong page when i clicked at the content there当我点击那里的内容时,LaTeX hyperref 链接转到错误的页面
【发布时间】:2018-08-30 08:26:44
【问题描述】:

我想问一下如何使用 \hyperref,因为我已经用谷歌搜索了很多答案,但我找不到。我创建了自己的目录。然后我包括 \hyperref 包。然后内容自动成为超链接,这很好。但后来它去了错误的页面。我用谷歌搜索了很多,但我找不到答案。我点击的内容进入了错误的页面。

\documentclass[10pt,a4paper]{report}

\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{enumerate}

\usepackage{hyperref}
% %\usepackage[colorlinks]{hyperref}


% %\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
% %\renewcommand*{\contentsname}{\hyperref[contents]{\arabic{page}}}

\begin{document}

\input{coverPage}
\maketitle

\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}
\pagebreak

\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
\pagebreak

% % (1) ==============================================
\setcounter{chapter}{1}
\addcontentsline{toc}{chapter}{1. Introduction}
\input{introduction}
\pagebreak

\addcontentsline{toc}{chapter}{2. References}
\input{references}
\pagebreak

\addcontentsline{toc}{chapter}{3. Glossary}
\input{glossary}
\pagebreak

\end{document}

【问题讨论】:

  • 使用\cleardoublepage\phantomsection\addcontentsline{toc}{chapter}{\contentsname}\tableofcontents。更大的问题是:为什么要手动插入?
  • @Werner 我的讲师认为我们应该如何做到这一点.. 我不知道添加内容的任何其他更好的方法.. 大声笑除了这种手动方式之外还有其他自动方式吗?
  • 您应该使用\chapter{<chap title>} 插入章节。我猜你在introduction.tex 和其他人内部做了一些不同的事情。
  • @Werner 你想写一个答案吗?还是因为不清楚?

标签: latex tex tableofcontents hyperref


【解决方案1】:

这里的问题是\chapter 将自己设置在一个新页面上,因此发出\addcontentsline{toc}{chapter}{<chapter title>} 之前 \chapter 可能指向错误的页面。

另外,您的\tableofcontents 可能不止一个页面。因此,发出\addcontentsline{toc}{chapter}{Table of Contents} 之后 \tableofcontents - 一个\chapter* - 可能会再次指向错误的页面。

最好的解决方案是使用以下设置:

\cleardoublepage
\addcontentsline{toc}{chapter}{<chapter title>}
% <your \chapter or \chapter*>

这将确保\addcontentsline\chapter\chapter* 在同一页面上发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    相关资源
    最近更新 更多