1

Consider this minimum working example. For example, some text is supposed to link to chapter 2.2, but links to chapter 1.2 instead. Here is the code:

\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}

Can anyone redirect the links to the correct places? Thank you!

1 Answer 1

2

Don't reset the counter manually inside \part, use \counterwithin, then hyperref can take care to setup its internal data:

\documentclass{book}
\usepackage{hyperref}
\counterwithin{chapter}{part}
\begin{document}
\tableofcontents
\part{A}
\chapter{chapter}

\part{B}
\chapter{chapter}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .