beamer 上的自定义部分没有超链接

beamer 上的自定义部分没有超链接

我正在处理一份 beamer 文档,其中有很多示例。我编写了几个宏,这些宏会自动添加带有“示例 #”的框架标题,并将这些框架添加到目录中以方便导航。但是,这些“示例 #”没有超链接到目录中的各自框架,但如果我在文档的其他地方引用它们,它们就会正确链接。这是我的 MWE 代码:

\documentclass[10pt,
hyperref={
%bookmarks=true,
linktocpage=true,
linktoc=all,
implicit=true,
%hypertexnames=false,
%debug
final=true
%
},
    handout
    ]{beamer}

\usepackage[spanish.noindentfirst,shorthands=off]{babel}
    \accentedoperators
    \decimalpoint

\usepackage[utf8]{inputenc}

\useoutertheme{infolines}
\usecolortheme{spruce}

\setbeamertemplate{headline}{
    \leavevmode\hbox{
    \begin{beamercolorbox}
    [wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{section in head/foot}%
    \usebeamerfont{section in head/foot}\inserttitle: ~\insertsubtitle\hspace*{2ex}
    \end{beamercolorbox}%
    \begin{beamercolorbox}
    [wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{subsection in head/foot}%
    \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsectionhead
    \end{beamercolorbox}}%
    \vskip0pt}
\setbeamertemplate{footline}{}
\mode<handout>{\setbeamertemplate{footline}[frame number]}
\setbeamertemplate{blocks}[rounded]
\setbeamertemplate{itemize item}{\color{mygreen}$\blacktriangleright$}
\setbeamertemplate{enumerate item}[circle]
\setbeamercolor{local structure}{fg=mygreen}
\setbeamertemplate{theorems}[numbered]

\def\subsubsectionname{Example}
\newcounter{ejc}
\newcommand{\ExFr}[1][\empty]{
    \refstepcounter{ejc}
    \phantomsection
    \label{#1}
    \frametitle{Example ~\theejc}
    \addcontentsline{toc}{subsection}{\quad Example ~\theejc\\}}
\newcommand{\ExFrC}{
    \frametitle{Example ~\theejc}}
\resetcounteronoverlays{ejc}

\usepackage[most]{tcolorbox}
    \colorlet{mygreen}{green!16!gray}

\title{A}
\subtitle{B}
\date{}

\setcounter{ejc}{16}

\begin{document}

\frame[plain]{\titlepage}
 
\section*{Contents}

\begin{frame}<beamer:0>%On handout only
\begin{columns}[t]
    \begin{column}{.5\textwidth}\tableofcontents[sections={2-}]\end{column}
    \begin{column}{.5\textwidth}
    %\tableofcontents[sections={2-4}]
    \end{column}
\end{columns}
\end{frame}

\section{Math}

\begin{frame}
\ExFr[arbpar]%
$1+1=2$
\end{frame}

\begin{frame}
\ExFrC
Also $1+2=3$.
\end{frame}

\begin{frame}
Wow.
\end{frame}

\begin{frame}
\ExFr
Remember example \ref{arbpar}.
\end{frame}

\end{document}

所以最后\ref提供了指向相应框架的可点击超链接,但我无法让 toc 执行此操作。如您所见,我一直在尝试各种选项,但似乎都不起作用。任何帮助都非常感谢!

答案1

你可以在将练习添加到目录中时添加链接,如下所示:

\documentclass[10pt,handout]{beamer}

\usepackage[spanish.noindentfirst,shorthands=off]{babel}
    \accentedoperators
    \decimalpoint

\usepackage[utf8]{inputenc}

\useoutertheme{infolines}
\usecolortheme{spruce}

\setbeamertemplate{headline}{
    \leavevmode\hbox{
    \begin{beamercolorbox}
    [wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{section in head/foot}%
    \usebeamerfont{section in head/foot}\inserttitle: ~\insertsubtitle\hspace*{2ex}
    \end{beamercolorbox}%
    \begin{beamercolorbox}
    [wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{subsection in head/foot}%
    \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsectionhead
    \end{beamercolorbox}}%
    \vskip0pt}
\setbeamertemplate{footline}{}
\mode<handout>{\setbeamertemplate{footline}[frame number]}
\setbeamertemplate{blocks}[rounded]
\setbeamertemplate{itemize item}{\color{mygreen}$\blacktriangleright$}
\setbeamertemplate{enumerate item}[circle]
\setbeamercolor{local structure}{fg=mygreen}
\setbeamertemplate{theorems}[numbered]

\def\subsubsectionname{Example}
\newcounter{ejc}
\newcommand{\ExFr}[1][\empty]{
    \refstepcounter{ejc}
    \phantomsection
    \label{exercise-\theejc}
    \label{#1}
    \addtocontents{toc}{\quad\hyperlink{exercise-\theejc}{Example ~\theejc}\\}
  \frametitle{Example ~\theejc}
}

\newcommand{\ExFrC}{
    \frametitle{Example ~\theejc}}
\resetcounteronoverlays{ejc}

\usepackage[most]{tcolorbox}
    \colorlet{mygreen}{green!16!gray}

\title{A}
\subtitle{B}
\date{}

\setcounter{ejc}{16}

\begin{document}

\frame[plain]{\titlepage}
 
\section*{Contents}

\begin{frame}<beamer:0>%On handout only
\begin{columns}[t]
    \begin{column}{.5\textwidth}\tableofcontents[sections={2-}]\end{column}
    \begin{column}{.5\textwidth}
    %\tableofcontents[sections={2-4}]
    \end{column}
\end{columns}
\end{frame}

\section{Math}

\begin{frame}
\ExFr[arbpar]%
$1+1=2$
\end{frame}

\begin{frame}
\ExFrC
Also $1+2=3$.
\end{frame}

\begin{frame}
Wow.
\end{frame}

\begin{frame}
\ExFr
Remember example \ref{arbpar}.
\end{frame}

\end{document}

相关内容