ビーマーのハイパーリンク(自動参照付き)の色

ビーマーのハイパーリンク(自動参照付き)の色

次の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ロードされます。つまり、 のロードは早めに停止され、重要な部分はロードされません。したがって、方程式はアンカーを生成しません。アンカーがなければリンクはありません (少なくとも、リンクが配置されるべき場所へのリンクはありません)。アンカー名がなければ はありません。hyperrefimplicit=falsehyperref\autoref

回避策は 2 つの部分で構成されます。

  • アンカーは で設定されます。は の設定を持つ のスタブにすぎない\phantomsectionため、アンカー名は重要ではありません。ただし、 もダミーの空のマクロであるため、例では を定義し、 は を使用してアンカーを設定します。\autoref\refbeamer\phantomsection\phantomtarget\hypertarget
  • \hyperrefオプションの引数 with は、リンク内の名前と番号を含む長いフレーズでプレーンな参照番号を置き換えるために使用されます。\ref*with star は、不要なネストされたリンクを防止します。

完全な例:

\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}

結果

関連情報