I've this problem where an Exercise environment automatically generates a reference to its Solution, and while the page displayed is correct, clicking on it leads to the Solution's chapter (if any) or does nothing if there's no chapter.

Minimal example:



  {\begin{innerexercise}\label{#1} (p.~\pageref{sol:#1}) \renewcommand{\Currentlabel}{#1}}

\newtheorem*{innersolution}{Solution{} \exerciseref}
   \innersolution\label{sol:#1} (p.~\pageref{#1})}


 First exercise here.
 \begin{sol} % label is auto generated: sol:firstexercise
 First solution here.

 \newpage % forcing break between one solution and another so to display two solutions in two different pages


 Second exercise here.
  Second solution here.



This code creates two environments, Exercise and Solution (which simply hold the two environments that do the actual work, "exercise" and "solution"; this extra layer is for code clarity in case one wants to add some graphical embellishments).

"Exercise" takes one argument, which then becomes its label. Inside an Exercise one has to define a "sol" environment which hosts its parent exercise's solution.

This code automatically generates references from Exercise A to its solution and vice versa.

Solutions aren't displayed inside their exercises: they are generated and grouped in a solution file (here, "solutions").

This code was generated thanks to community help as seen in my previous question here: Cross-reference two numbered environments

So, here's the issue. This minimal example generates two exercises and two solutions:


The page references are correct, so one'd assume they'd point to the correct pages too. That is not the case: they do nothing. What's going on?

1 Answer 1


When setting a \label, hyperref uses the last mark as the hyper-target. If you don't specify this in the correct way, your links might end up where they shouldn't go.

You can place a \phantomsection inside your solution environment. This re-establishes the hyper-target location:

   \innersolution\phantomsection\label{sol:#1} (p.~\pageref{#1})}

You must log in to answer this question.

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