新答案

新答案
\documentclass{article}
\usepackage{amsmath}
\usepackage{showframe}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
    Some text before the subequations.
    \clearpage
    \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}

在此处输入图片描述

单击超链接会将我带到子方程式之前的一行。我怎样才能让链接将我带到子方程式 (eq 1a) 的第一行?我希望 cref 仍然显示为,因为eq. (1)我指的是整个子方程式集。

编辑: 当子方程式出现在页面开始时,它也应该起作用。

答案1

新答案

环境问题subequations在于这不是一个数学环境.subequations环境仅仅改变了柜台编号方程。

因此,当为主文本创建超链接锚点时subequations,其位置实际上位于前一行最后一行文本的基线。要查看此内容,请取消注释\setlength\HyperRaiseLinkLength{0pt}下面解决方案中的行。

因此,如果环境之前有分页符subequations,超链接锚点就无处可去,只能去新页面中文本主体的左上角。hyperref在这种情况下,我们能做的不多。我们可以重写文本:

  1. 使其更长,以便一到两行内容可以延续到下一页;
  2. 使其更短并使用\allowdisplaybreaks以便第一行subequations适合上一页。

无论如何,避免用方程式开始新的一页。

解决了令人不快的“新页面”情况后,我提供了一种移动超链接锚点的新实现。现在,方程 (1) 和 (1a) 的超链接指向精确的同一个地方!

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

超链接


旧答案

一个极其肮脏的黑客行为:

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

答案2

您可以将实际标记向下移动 2 个基线跳过(1 个用于抵消默认提升,另一个用于将其带到第一个等式),然后使用以下命令强制新的目标\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}

我们使用\raisebox得到0pt的深度和0pt高度(类似于\smash)。

相关内容