%20no%20beamer.png)
Considere o seguinte 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}
Quero que i) os parênteses em torno do número da equação façam parte do hiperlink (e, portanto, também sejam destacados em azul) e ii) comecem \autoref
a funcionar (e, portanto, obtenham também Equation (1) belongs to Theorem (1)
destacado em azul).(1)
Theorem (1)
Editar:Considere o seguinte MWE que incorpora a solução sugerida na resposta única a esta pergunta:
\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}
Os hiperlinks sempre apontam para o primeiro quadro e não para a equação ou teorema correspondente.
Responder1
A classe beamer
carrega hyperref
com a opção implicit=false
. Isso significa que o carregamento hyperref
é interrompido mais cedo e as peças importantes não são carregadas. Assim, as equações nem sequer geram âncoras. Sem âncora não há link (pelo menos não para o local onde deveria ir), sem nome de âncora não \autoref
.
A solução alternativa consiste em duas partes:
- As âncoras são definidas com
\phantomsection
. Os nomes das âncoras não importam de qualquer maneira, porque\autoref
é apenas um esboço\ref
dasbeamer
configurações. Porém, também\phantomsection
é uma macro fictícia, uma macro vazia, portanto o exemplo define a\phantomtarget
, que define uma âncora usando\hypertarget
. \hyperref
com argumento opcional é usado para substituir o número de referência simples pela frase mais longa com nome e número, ambos dentro do link.\ref*
com estrela evita um link aninhado desnecessário.
Exemplo 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}