当我点击“目录”书签时,它会带我进入“致谢”部分。当我点击“致谢”时,它会带我进入“致谢”部分,这是正确的,但为什么当我点击书签“目录”时它会带我进入“目录”部分?我的代码是这样的
\documentclass[sfdefaults=false,12pt]{article}
\usepackage{report}
\usepackage[acronym]{glossaries}
\usepackage{rotating}
\usepackage{float}
\usepackage{siunitx}
\usepackage{array}
\usepackage{cite}
\usepackage[justification=centering]{caption}
\usepackage{booktabs}
\usepackage[table,xcdraw]{xcolor}
\usepackage{chngcntr}
\usepackage[utf8]{inputenc}
\usepackage{subcaption}
\usepackage{sectsty}
\usepackage{fancyhdr}
\usepackage{mwe}
\usepackage{titlesec}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{alphabeta}
\usepackage{hyperref}
\usepackage{csquotes}
\graphicspath{{./sec/image/}}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\makeatletter
\newcommand\subsubsubsection{\@startsection{paragraph}{4}{\z@}{-2.5ex\@plus -1ex \@minus -.25ex}{1.25ex \@plus .25ex}{\normalfont\normalsize\bfseries}}
\newcommand\subsubsubsubsection{\@startsection{subparagraph}{5}{\z@}{-2.5ex\@plus -1ex \@minus -.25ex}{1.25ex \@plus .25ex}{\normalfont\normalsize\bfseries}}
\makeatother
\date{\today}
%\renewcommand*{\sectionformat}{}% Don't print section number in section titles.
\sectionfont{\centering}
\onehalfspacing
\begin{document}
\fancyhead{}
\fancyfoot[C]{\thepage}
\input{sec/titlepage}
\newpage
\pagenumbering{Roman} % roman page numbers
\input{sec/second_page} % The page next to Title Page
\input{sec/approval_sheet}
\input{sec/declaration}
\input{sec/acknowledgment}
\newpage
\setlength{\parskip}{0em}
\renewcommand\contentsname{\centering TABLE OF CONTENTS}% This will change heading text
\addcontentsline{toc}{section}{TABLE OF CONTENTS}
\cleardoublepage
\phantomsection
\tableofcontents
% List of figures - if any
\newpage
\listoffigures
\addcontentsline{toc}{section}{LIST OF FIGURES}
% List of tables- if any
\newpage
\listoftables
\addcontentsline{toc}{section}{LIST OF TABLES}
% List of Abbreviation- if any
\input{sec/abbreviations}
%Abstract
\input{sec/abstract}
%Begining of Main Body
\newpage
\input{sec/introduction}
\input{sec/literature_review}
\input{sec/methodology}
% \input{sec/result}
%\input{sec/conclusion}
\input{sec/references}
% \input{sec/appendix} %optional
\end{document}
答案1
您需要更改所用命令的顺序。不要先使用\addcontentsline
,然后使用\phantomsection
,而是先创建phantomsection
,然后使用addcontentsline
,这样超链接就会锚定到最后phantomsection
创建的 。
您还需要对添加到书签中的其他内容列表执行此操作。