%20en%20Beamer.png)
Considere el siguiente 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}
Quiero que i) los paréntesis alrededor del número de ecuación sean parte del hipervínculo (y por lo tanto también estén resaltados en azul) y ii) ponerse \autoref
a trabajar (y por lo tanto obtener Equation (1) belongs to Theorem (1)
con (1)
también Theorem (1)
resaltado en azul).
Editar:Considere el siguiente MWE que incorpora la solución sugerida en la respuesta única a esta pregunta:
\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}
Los hipervínculos siempre apuntan al primer cuadro y no a la ecuación o teorema correspondiente.
Respuesta1
La clase beamer
se carga hyperref
con opción implicit=false
. Esto significa que la carga hyperref
se detiene antes y las piezas importantes no se cargan. Por tanto, las ecuaciones ni siquiera generan anclajes. Sin ancla no hay enlace (al menos no al lugar donde debe ir), sin nombre de ancla no \autoref
.
La solución consta de dos partes:
- Las anclas se fijan con
\phantomsection
. Los nombres de los anclajes no importan de todos modos, porque\autoref
son solo un código auxiliar para\ref
labeamer
configuración. Sin embargo, también\phantomsection
es una macro ficticia, vacía, por lo que el ejemplo define a\phantomtarget
, que establece un ancla usando\hypertarget
. \hyperref
con argumento opcional se utiliza para reemplazar el número de referencia simple por la frase más larga con nombre y número, ambos dentro del enlace.\ref*
con estrella evita un enlace anidado innecesario.
Ejemplo completo:
\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}