latex 跳转标签,LaTeX hyperref链接转到错误的页面

I am trying to create a reference to a float that doesn't use a caption. If I include \label{foo} within the float and reference it using \pageref{foo}, the correct page number is displayed in my pdf document but the hyperlink created by the hyperref package links to a different page (the first page of the section). If I include a caption before the label in the float, the hyperref link goes to the correct page.

Is there a way to get the hyperref link to work correctly without including a caption in the float? Or else is there a way to suppress the display of a caption so I can include one without it being shown?

Below is a minimal example. If I process it using pdflatex, I get three pages. The "figure" is shown on the second page, and the third page says, correctly, "See figure on page 2." But the hyperlink on the '2' says "Go to page 1", and if I click it it takes me to page 1.

If I put an empty \caption{} before the \label{foo}, then the hyperlink works correctly, but I don't want to show a caption for my float.

\documentclass[11pt]{memoir}

\usepackage{hyperref}

\begin{document}

some text

\clearpage

\begin{figure}

a figure

\label{foo}

\end{figure}

more text

\clearpage

See figure on page \pageref{foo}.

\end{document}

解决方案

The \label command references the last invocation of \refstepcounter. \caption recognises that it is in a figure environment and calls \refstepcounter{figure}. You can call \refstepcounter by yourself.

To avoid skipping a number in the series of figures, you may create an own, meaningless counter with \newcounter{dummy}. The result:

\documentclass{scrreprt}

\usepackage{hyperref}

\newcounter{dummy}

\begin{document}

\chapter{First}

\newpage

\begin{figure}

{\Huge FIGURE}

\refstepcounter{dummy}

\label{fig:figure}

\end{figure}

\chapter{Second}

Goto \pageref{fig:figure}

\end{document}

Creates an hyperlink to the end of the figure. (works on my machine :-)

Note than \ref{fig:figure} is meaningless.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值