1

In this MWE, the link created by hyperref points to the first page but should point to the second page.

How can I fix this issue?

\documentclass{article}
\usepackage{hyperref}
\usepackage{varioref}

\newcounter{counterOne}
\newcounter{counterTwo}
\renewcommand{\thecounterTwo}{\alph{counterTwo}}
\labelformat{counterTwo}{\textbf{\thecounterOne.#1)}}


\begin{document}
\refstepcounter{counterOne}
\refstepcounter{counterTwo}


\section{Part 1}
\begin{itemize}
\item
\label{first} This is the first point

\item
\label{second} This is the second point
\end{itemize}

\newpage
\section{Part 2}

\setcounter{counterTwo}{0}
\refstepcounter{counterOne}
\refstepcounter{counterTwo}

\begin{itemize}
\item
\label{third} This is the third point
\end{itemize}

\newpage
\section{Part 3}

It was \ref{third}.

\end{document}

enter image description here

(the picture shows where the link should point to)

2
  • What's the point of using \label in itemize?
    – egreg
    Jan 31, 2021 at 13:31
  • It is just for the MWE.
    – Colas
    Jan 31, 2021 at 14:03

1 Answer 1

0

Followin this answer to another question, here is a solution:

\documentclass{article}
\usepackage{hyperref}
\usepackage{varioref}

\newcounter{counterOne}
\newcounter{counterTwo}
\newcounter{counterTotal}
\renewcommand{\thecounterTwo}{\alph{counterTwo}}
\labelformat{counterTotal}{\textbf{\thecounterOne.\thecounterTwo)}}


\begin{document}
\refstepcounter{counterOne}
\refstepcounter{counterTwo}
\refstepcounter{counterTotal}


\section{Part 1}
\begin{itemize}
\item
\label{first} This is the first point

\item
\label{second} This is the second point
\end{itemize}

\newpage
\section{Part 2}

\setcounter{counterTwo}{0}
\refstepcounter{counterOne}
\refstepcounter{counterTwo}
\refstepcounter{counterTotal}

\begin{itemize}
\item
\label{third} This is the third point
\end{itemize}

\newpage
\section{Part 3}

It was \ref{third}.

\end{document}
2
  • 1
    It's not clear what you're trying to demonstrate here. Since itemize doesn't increment a counter, the arguments of \label{first} and \label{second} are associated with the most recently incremented counter, which happens to be the section counter (with value 1). Later, \label{third} gets associated with the counterTotal counter (with value 2). However, because of the earlier \labelformat{counterTotal}{...} directive, the output of \ref{third} is a composite of the values of counterOne and counterTwo. What does 2.a) stand for, and what are you trying to achieve?
    – Mico
    Jan 31, 2021 at 14:54
  • I want to manage by myself : a series of chapters and in each chapter a series of exercises.
    – Colas
    Jan 31, 2021 at 17:17

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