You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现LaTeX公式跳转链接点击后公式居中显示?

实现点击公式跳转后公式居中显示

可以实现该需求,以下提供几种实用方法:

方法1:手动添加垂直填充

在公式环境前后添加垂直填充,将公式推至屏幕中央。修改代码如下:

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath}
\begin{document}

\section{Introduction}
\newpage
\section{Introduction1}
% 用垂直填充将公式调整到屏幕中央
\vfill
\begin{equation}\label{eq:1} 
a = b + c +d \cdot a
\end{equation}
\vfill
\newpage
\section{Introduction2}
\newpage
\section{Introduction3}
\eqref{eq:1}
\newpage
\end{document}

这种方式简单直接,适合单个公式的场景,可根据实际显示效果微调填充量。

方法2:自定义公式环境调整锚点

通过自定义公式环境,计算并设置锚点的垂直偏移量,让跳转后公式自动居中:

\documentclass{article}
\usepackage[pdfadjustspacing=false]{hyperref}
\usepackage{amsmath}

% 自定义居中公式环境,自动计算偏移量
\newenvironment{centeredequation}
  {\vspace{\dimexpr0.5\textheight - 0.5\baselineskip - 0.5\heightof{$a=b$}}\begin{equation}}
  {\end{equation}}

\begin{document}

\section{Introduction}
\newpage
\section{Introduction1}
\begin{centeredequation}\label{eq:1} 
a = b + c +d \cdot a
\end{centeredequation}
\newpage
\section{Introduction2}
\newpage
\section{Introduction3}
\eqref{eq:1}
\newpage
\end{document}

偏移量基于屏幕高度的一半,减去公式高度和基线间距的一半,确保公式垂直居中。

方法3:手动设置跳转锚点

用\hypertarget在公式上方合适位置设置锚点,让引用链接跳转到该锚点:

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath}
\begin{document}

\section{Introduction}
\newpage
\section{Introduction1}
% 计算偏移量后设置锚点
\vspace{\dimexpr0.5\textheight - 0.5\heightof{$a=b+c+d\cdot a$}}
\hypertarget{eq:1}{}
\begin{equation}\label{eq:1} 
a = b + c +d \cdot a
\end{equation}
\newpage
\section{Introduction2}
\newpage
\section{Introduction3}
% 链接到自定义锚点
\hyperlink{eq:1}{\ref{eq:1}}
\newpage
\end{document}

此方法能精确控制跳转位置,需手动关联锚点与引用。

注:不同PDF阅读器的显示效果可能略有差异,可根据实际情况微调偏移参数。

内容的提问来源于stack exchange,提问作者tovernaar123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 01:27:12