目录链接到错误的页面 + 错误的标题名称

目录链接到错误的页面 + 错误的标题名称

面临被归类为重复的风险,由于原始海报内容混乱,而且我对该语言还不熟悉,所以我发现很难理解,所以我会问类似的问题。

我正在使用从大学网站下载的模板撰写论文。以下是(删节的)故障代码:

\documentclass[12pt]{book}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Additional packages  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[bookmarks]{hyperref}
\usepackage{a4wide}
\usepackage{fancyhdr}
\usepackage{graphicx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Definition of the Header %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pagestyle{fancyplain}
\renewcommand{\chaptermark}[1]%
{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]%
{\markright{\thesection\ #1}}
\lhead[\fancyplain{}{\bfseries\thepage}]%
{\fancyplain{}{\bfseries\rightmark}}
\rhead[\fancyplain{}{\bfseries\leftmark}]%
{\fancyplain{}{\bfseries\thepage}}
\cfoot{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Beginning of Dokument  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{document}
    \frontmatter

    \tableofcontents
    \markboth{Contents}{Contents}

    \listoffigures
    \markboth{List of Figures}{List of Figures}

    \cleardoublepage

    \markboth{Abstract}{Abstract}
    \addcontentsline{toc}{chapter}{\protect Abstract}
    \chapter*{Abstract}
    Here is a maximum one-page summary of Dissertation.

    \cleardoublepage

    \addcontentsline{toc}{chapter}{\protect Acknowledgement}
    \chapter*{Acknowledgement}
    Thank you.


    \mainmatter\setcounter{page}{1}
    \chapter{First Chapter}
    Shakespeare: What is in a name? That which you call a chick, by any other name would smell as sweet.

\end{document}

您看到的问题有两个方面。首先,目录似乎没有正确链接到摘要和致谢。其次,观察(在编译的 PDF 中)致谢后的空白页 (viii) 的页眉。它仍然显示摘要。

我尝试在各个部分插入\phantomsection,但似乎无法解决问题。请帮忙。

非常感谢。

答案1

您必须\phantomsection先使用\addcontentsline

\documentclass[12pt]{book}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Additional packages  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{a4wide}% really old package, I would suggest to use geometry
\setlength{\headheight}{14.5pt}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage[bookmarks]{hyperref}% <- moved to load as last package
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Definition of the Header %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pagestyle{fancyplain}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhead[LE,RO]{\fancyplain{}{\bfseries\thepage}}%<- changed
\fancyhead[RE]{\fancyplain{}{\bfseries\nouppercase{\leftmark}}}% <- changed
\fancyhead[RO]{\fancyplain{}{\bfseries\nouppercase{\rightmark}}}% <- changed
\fancyfoot{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Beginning of Dokument  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\frontmatter
\tableofcontents
\listoffigures

\cleardoublepage
\phantomsection% <- added
\addcontentsline{toc}{chapter}{Abstract}
\markboth{Abstract}{Abstract}
\chapter*{Abstract}
Here is a maximum one-page summary of Dissertation.

\cleardoublepage
\phantomsection% <- added
\addcontentsline{toc}{chapter}{Acknowledgement}
\markboth{Acknowledgement}{Acknowledgement}%<- added
\chapter*{Acknowledgement}
Thank you.

\mainmatter% resets the page number automatically
\chapter{First Chapter}
\end{document}

相关内容