我有一个很长的文章类文档(约 300 页)。目录中的链接经常会错过文档中的目标几页。当我缩短文档时,问题就消失了,这样我就无法制作最小工作示例。但是,单击目录中的“第一部分”链接即可看到此行为这里如果我的描述不够充分,它会跳转到第 28 页,而它应该跳转到第 30 页。由于我怀疑问题是由于软件包冲突引起的,所以我包含了整个标题,而没有删除(在我看来)不相关的内容。
如果有办法除了章节标题本身之外,还能为目录中的链接添加特定目标标签,那可能是最简单的方法了。谢谢!
\documentclass[letterpaper,twoside,notitlepage]{article}
\setcounter{tocdepth}{2}
\usepackage[left=1.25in,right=1.25in,top=1.25in,bottom=1.25in,centering]{geometry}
\usepackage{setspace}
\usepackage[hang,font=singlespacing,font=large]{caption}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{amssymb,amsmath}
\usepackage{mathrsfs}
\usepackage{stackrel}
\usepackage{titling}
\usepackage[perpage]{footmisc}
\usepackage{cite}
\usepackage{titlesec}
\usepackage{enumitem}
\usepackage{bbm}
\usepackage{mathtools}
\usepackage{centernot}
\usepackage[hyphens,spaces,obeyspaces]{url}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tocloft}
\renewcommand{\cftdot}{}
\renewcommand{\contentsname}{\hfill\bfseries\Large \underline{\underline{$\,\qquad\qquad\qquad\qquad$Contents$\qquad\qquad\qquad\qquad$}}\hfill\newline}
\renewcommand{\cftaftertoctitle}{\hfill}
\setlength{\cftbeforesecskip}{1ex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[hidelinks]{hyperref}
\newif\iffirst\firsttrue %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}
\fancypagestyle{762style}{%
\fancyhf{}
\cfoot{\thepage}
\fancyhead[OC]{\textsc{FAKE NAME}}
\fancyhead[EC]{\textsc{FAKE TITLE}}
\renewcommand{\headrulewidth}{0pt}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titletoc}
%%%%%% NO SECTION NUMBERS IN TOC %%%%%%%%%%%%
\makeatletter
\let\latexl@section\l@section
\def\l@section#1#2{\begingroup\let\numberline\@gobble\latexl@section{#1}{#2}\endgroup}
\let\latexl@subsection\l@subsection
\def\l@subsection#1#2{\begingroup\let\numberline\@gobble\latexl@subsection{#1}{#2}\endgroup}
\makeatother
\title{FAKE TITLE}
\author{FAKE NAME}
\begin{document}
\begin{minipage}{\textwidth}
\maketitle
\thispagestyle{empty}
\begin{abstract}
FAKE TEXT
\end{abstract}
\end{minipage}
\pagenumbering{gobble}
\raggedbottom
\newpage
\newgeometry{left=2in,right=2in,top=1.4in,bottom=1.4in}
\large{
\tableofcontents
\restoregeometry
\newpage
\pagenumbering{arabic}
\pagestyle{762style}
\setcounter{page}{1}
\renewcommand{\baselinestretch}{1.2}\normalsize
这就是我用作示例的“第一部分”标题的排版方式。
\section*{\underline{Part I: The Modified Cosmological Model}}
\addcontentsline{toc}{section}{\underline{Part I: The Modified Cosmological Model}}
根据 Ulrike 的有益评论,我发现只有这些未编号的部分存在问题。这是一个链接准确的(编号)部分。
\section{The $\boldsymbol{\hat M^3}$ Operator and its Equation}\label{sec:M3}
答案1
正如 hyperref 文档所述,如果使用此包,titlesec 仅部分受支持,并且未编号的部分会丢失锚点。您可以使用\phantomsection
\documentclass{article}
\usepackage{titlesec}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{abc}
abc\newpage
\section*{\phantomsection\underline{Part I: The Modified Cosmological Model}}
\addcontentsline{toc}{section}{\underline{Part I: The Modified Cosmological Model}}
\end{document}