Cor dos hiperlinks (com autoref) no beamer

Cor dos hiperlinks (com autoref) no beamer

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 \autorefa funcionar (e, portanto, obtenham também Equation (1) belongs to Theorem (1)destacado em azul).(1)Theorem (1)

insira a descrição da imagem aqui

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 beamercarrega hyperrefcom 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 \refdas beamerconfiguraçõ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.
  • \hyperrefcom 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}

Resultado

informação relacionada