Hyperref with align inside subequations
You can move the actual mark down by 2 baseline skips (1 to counter the default raise and another to bring it to the first equation) and then force a new target using \phantomsection
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
Some text before the subequations.
\begin{subequations}
\raisebox{-2\baselineskip}[0pt][0pt]{%
\phantomsection % Set new hyper target
\label{eq:arithmetic} % Mark label
}
\begin{align}
a + b &= c \\
a + b &= c \\
a + b &= c \\
a + b &= c
\end{align}
\end{subequations}
The reference to the main equation with \cref{eq:arithmetic} brings me to a line before the set of subequations.
\end{document}
We use \raisebox
with a 0pt
resulting depth and 0pt
height (similar to \smash
).
New answer
The problem with the subequations
environment is that it is not a math environment. The subequations
environment merely changes the behavior of the counter of numbered equations.
As a result, when a hyperlink anchor is created for the main subequations
, its position is actually on the baseline of the previous last line of text. To see this, uncomment the line \setlength\HyperRaiseLinkLength{0pt}
in the solution below.
So, if there is a page break before the subequations
environment, the hyperlink anchor has nowhere to go but the upper-left corner of the text body in the new page. There isn’t much hyperref
can do in this case. We could rewrite the text:
- Make it longer so one or two lines follow onto the next page;
- Make it shorter and use
\allowdisplaybreaks
so the first line ofsubequations
fits in the previous page.
In any case, avoid starting a new page with equations.
With the unpleasant “new page” situation out of the way, I provide a new implementation of shifting the hyperlink anchor. Now, the hyperlinks for eqs. (1) and (1a) point to the exact same spot!
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}
% Let's patch \HyOrg@subequations from hyperref
\usepackage{etoolbox}
\makeatletter
% Change \HyperRaiseLinkLength for the main anchor in subequations
\preto\HyOrg@subequations{%
\renewcommand*\HyperRaiseLinkHook{%
% Drop the main anchor from the baseline of previous text by \abovedisplayskip
\setlength\HyperRaiseLinkLength{-\abovedisplayskip}%
% Then, raise the main anchor by 3pt
% (The 3pt is to cancel the -\lineskip from \displ@y, see amsldoc.tex)
\addtolength\HyperRaiseLinkLength{3pt}%
% To see the default position of the main anchor, uncomment the following line:
%\setlength\HyperRaiseLinkLength{0pt}%
}%
}
% Change nothing for the other anchors in subequations
\appto\HyOrg@subequations{%
\let\HyperRaiseLinkHook\@empty
}
\makeatother
\begin{document}
Some text before the subequations.
\begin{subequations}\label{eq:arithmetic}
\begin{align}
a + b &= c \label{eq:arithmetic-a} \\
a + b &= c \label{eq:arithmetic-b} \\
a + b &= c \nonumber \\
a + b &= c \label{eq:arithmetic-c}
\end{align}
\end{subequations}
Testing:
\Cref{eq:arithmetic,eq:arithmetic-a} bring me to the \emph{exact} same place,
while \cref{eq:arithmetic-b,eq:arithmetic-c} bring me to the correct subequations.
\begin{equation}
e^{i\pi} = -1 \label{eq:euler}
\end{equation}
Testing:
\Cref{eq:euler} bring me to Euler's identity.
\end{document}
Old answer
An extremely dirty hack:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}
% Since you have loaded cleveref, we can patch \cref@old@subequations directly
\usepackage{etoolbox}
\makeatletter
% Vertical space No. 1:
\preto\cref@old@subequations{\vskip\abovedisplayskip\nobreak}
% Vertical space No. 2:
\appto\cref@old@subequations{\vskip-\abovedisplayskip\vskip-\baselineskip\nobreak}
\makeatother
\begin{document}
Some text before the subequations.
\begin{subequations}\label{eq:arithmetic}
\begin{align}
a + b &= c \\
a + b &= c \\
a + b &= c \\
a + b &= c
\end{align}
\end{subequations}
The reference to the main equation with \cref{eq:arithmetic} brings me to a line before the set of subequations.
\end{document}