考虑这个最小工作示例。例如,一些文本应该链接到第 2.2 章,但却链接到了第 1.2 章。以下是代码:
\usepackage[top=4cm,bottom=4cm,left=3cm,right=3cm,asymmetric]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{array}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{float}
\usepackage{soul}
\usepackage[dvipsnames, table]{xcolor}
\usepackage{tocloft}
\usepackage{afterpage}
\newcommand\blankpage{%
\null
\thispagestyle{empty}%
\addtocounter{page}{-1}%
\newpage}
\renewcommand\thefootnote{\textcolor{Cerulean}{\arabic{footnote}}}
\renewcommand\thefigure{\arabic{figure}}
\renewcommand\thetable{\arabic{table}}
\renewcommand\thechapter{\arabic{part}.\arabic{chapter}}
\setlength{\parindent}{0pt}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=black,
filecolor=purple,
urlcolor=Cerulean,
pdfpagemode=FullScreen,
}
\usepackage[
backend=biber,
style=alphabetic,
sorting=ynt
]{biblatex}
\usepackage{fancyhdr}
\usepackage{subcaption}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{e}
\fancyhead[LO]{f}
\fancyhead[LE, RO]{\thepage}
\usepackage[stable]{footmisc}
\begin{document}
\pagenumbering{arabic}
\part{A}
\newpage
\setcounter{chapter}{0}
\chapter{yes}
\label{sec:1.1}
\hyperref[sec:2.1]{\color{Cerulean}\underline{This is meant to link to chapter 2.1, and it just stays in place? (possibly links to chapter 1.1)}}\\
\hyperref[sec:2.2]{\color{Cerulean}\underline{This is meant to link to chapter 2.2, but links to chapter 1.2}}
\chapter{asdfuhoaisdhfoih}
\label{sec:1.2}
\part{E}
\setcounter{chapter}{0}
\chapter{no}
\label{sec:2.1}
\chapter{maybe}
\label{sec:2.2}
\end{document}
有人能将链接重定向到正确的位置吗?谢谢!
答案1
不要在里面手动重置计数器\part
,而是使用\counterwithin
,然后 hyperref 可以小心地设置其内部数据:
\documentclass{book}
\usepackage{hyperref}
\counterwithin{chapter}{part}
\begin{document}
\tableofcontents
\part{A}
\chapter{chapter}
\part{B}
\chapter{chapter}
\end{document}