%20%D0%B2%20Beamer.png)
Рассмотрим следующий 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
с необязательным аргументом используется для замены простого ссылочного номера более длинной фразой с именем и номером, находящимися внутри ссылки.\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}