“超目标”的页码

“超目标”的页码

显示图表或表格的页码\pageref很有用。但是,它不适用于\hypertarget

如果我需要显示超目标的页码怎么办?

例如:

The problem is explained in page ???? at \hyperlink{my-explanation}{here}

.
.
.

\hypertarget{my-explanation}
Explanation ....

试图:

\getpagerefnumber{my-explanation}不起作用并返回零。

答案1

与的答案类似touhami,但使用phantomsection\label来获取正确的锚点,全部组合成一个\pagetarget宏:

\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}

\newcommand{\pagetarget}[2]{%
  \phantomsection%
  \label{#1}%
  \hypertarget{#1}{#2}%
}


\begin{document}

The problem is explained in page \pageref{my-explanation} at \hyperlink{my-explanation}{here}

\blinddocument
\blindtext[2]
\pagetarget{my-explanation}{Explanation}

\blindtext[5]

\end{document}

答案2

您可以使用\label-\pageref

例子

\documentclass{article}
\usepackage{hyperref}

\usepackage{mwe}

\begin{document}

The problem is explained in page \pageref{my-explanation} at \hyperlink{my-explanation}{here}

\blinddocument

...
\hypertarget{my-explanation}{\label{my-explanation}Explanation} ....

\end{document}

相关内容