
考慮以下 MWE
\documentclass[leqno]{beamer}
\usepackage{lmodern}
\hypersetup{colorlinks=true,allcolors=blue}
\setbeamertemplate{theorems}[numbered]
\begin{document}
\begin{frame}
\begin{theorem}
\label{thm:a_theorem}
\begin{equation}
\label{eq:an_equation}
2 + 2 = 4
\end{equation}
\end{theorem}
Equation \ref{eq:an_equation} belongs to \ref{thm:a_theorem}.\\
Equation \eqref{eq:an_equation} belongs to \ref{thm:a_theorem}.\\
Equation \autoref{eq:an_equation} belongs to \autoref{thm:a_theorem}.
\end{frame}
\end{document}
我希望 i)方程式編號周圍的括號成為超連結的一部分(因此也以藍色突出顯示)和 ii)開始\autoref
工作(因此也以藍色突出Equation (1) belongs to Theorem (1)
顯示)。(1)
Theorem (1)
編輯:考慮以下 MWE,它將建議的解決方案納入該問題的唯一答案中:
\documentclass[leqno]{beamer}
\usepackage{lmodern}
\hypersetup{colorlinks=true,allcolors=blue}
\setbeamertemplate{theorems}[numbered]
\begin{document}
\begin{frame}
Foo
\end{frame}
\begin{frame}
\phantomsection
\begin{theorem}
\label{thm:a_theorem}
Bar
\end{theorem}
\end{frame}
\begin{frame}
\phantomsection
\begin{equation}
\label{eq:an_equation}
2 + 2 = 4
\end{equation}
\end{frame}
\begin{frame}
\hyperref[eq:an_equation]{Equation (\ref*{eq:an_equation})} belongs
to \hyperref[thm:a_theorem]{Theorem \ref*{thm:a_theorem}}.
\end{frame}
\end{document}
超連結始終指向第一幀,而不指向對應的方程式或定理。
答案1
類別beamer
載入hyperref
選項implicit=false
。這意味著提前停止加載hyperref
,重要部分不會加載。因此,方程式甚至不產生錨點。沒有錨點就沒有連結(至少不是到它應該去的地方),沒有錨點名稱就沒有\autoref
。
解決方法由兩部分組成:
- 錨點設定為
\phantomsection
。無論如何,錨點名稱並不重要,因為它只是設定\autoref
的存根。然而,它也是一個虛擬的空宏,因此該範例定義了,它使用 來設定錨點。\ref
beamer
\phantomsection
\phantomtarget
\hypertarget
\hyperref
with 可選參數用於將普通參考號碼替換為連結內包含名稱和編號的較長短語。\ref*
帶星號可防止不必要的嵌套連結。
完整範例:
\documentclass[leqno]{beamer}
\usepackage{lmodern}
\hypersetup{colorlinks=true,allcolors=blue}
\setbeamertemplate{theorems}[numbered]
\makeatletter
\newcounter{phantomtarget}
\renewcommand*{\thephantomtarget}{phantom.\the\value{phantomtarget}}
\newcommand*{\phantomtarget}{%
\stepcounter{phantomtarget}%
\hypertarget{\thephantomtarget}{}%
\edef\@currentHref{\thephantomtarget}%
}
\makeatother
\begin{document}
\begin{frame}
\phantomtarget
\begin{theorem}
\label{thm:a_theorem}
\phantomtarget
\begin{equation}
\label{eq:an_equation}
2 + 2 = 4
\end{equation}
\end{theorem}
\hyperref[eq:an_equation]{Equation (\ref*{eq:an_equation})} belongs
to \hyperref[thm:a_theorem]{Theorem \ref*{thm:a_theorem}}.
\end{frame}
\end{document}