向 AtBeginSection 幻灯片添加标签

向 AtBeginSection 幻灯片添加标签

我想将 放到\ref用 创建的幻灯片之一中\AtBeginSection,可以吗?

更详细地说,我滥用

\setbeamertemplate{background canvas}{%
\hspace{.8\textwidth}\includegraphics[width=.2\paperwidth,height=\paperheight]{./symmetry_breaking.pdf}
}

\subsection[shorttitle]{long title with \texorpdfstring{$x^2$}{x2} \label{sym}
}

\beamertemplateshadingbackground{blue!01!white}{white}

处理一张\AtBeginSubsection幻灯片上的背景图像。正如你所见,我尝试在那里贴上标签,这样在最后一张幻灯片上我可以问“谁发现幻灯片上的错误\ref{sym}?”

我可以在这些自动生成的幻灯片上贴标签吗?

(或者,我也愿意采取一种解决方法,将标签放在下一张幻灯片上,然后进行算术运算来找出之前的幻灯片编号。)

编辑:

目前我的文件看起来(缩减为 MWE)是这样的:

\documentclass{beamer}
\usepackage{graphicx}

\AtBeginSubsection[]
{
  \begin{frame}<beamer>{}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

\begin{document}

\section{recap}
\subsection{what do we want}

\begin{frame}{what do we want}
  \begin{itemize}
      \item we want it all
  \end{itemize}
\end{frame}

\setbeamertemplate{background canvas}{%
  {~}\hspace{.8\textwidth}\includegraphics[width=.2\paperwidth,height=\paperheight]{./symmetry_breaking.png}
}

\subsection[problem when you can zip]{problem when you can zip \label{sym}}

\beamertemplateshadingbackground{blue!01!white}{white}

\begin{frame}
  \frametitle{zipping solves everything}
  Lorem ipsum
\end{frame}

\subsection{1234}

\begin{frame}
  \frametitle{conclusion}
  \begin{itemize}
    \item headache ahead
    \item<2-> Bonus points for those who spotted the mistake on slide~\ref{sym}
  \end{itemize}
\end{frame}

\end{document}

其中包括这张图片

只是一个图像

(在转换过程中受到影响,但就这里的价值而言,可以是任何图像)。

我建立

rm -f pseyfert.aux pseyfert.toc pseyfert.snm
xelatex pseyfert.tex
xelatex pseyfert.tex
xelatex pseyfert.tex

最后一张幻灯片如下

在此处输入图片描述

并应注明“发现幻灯片 3 中的错误的人可获得加分”

答案1

如果您只需要为单个小节添加标签,另一种方法可能是暂时重新定义小节框架——当然,如果您需要为许多小节添加标签,这种方法就会变得麻烦。

\documentclass{beamer}

\AtBeginSubsection[]
{
  \begin{frame}<beamer>{}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

\begin{document}

\section{recap}
\subsection{what do we want}

\begin{frame}{what do we want}
  \begin{itemize}
      \item we want it all
  \end{itemize}
\end{frame}

\begingroup
\setbeamertemplate{background canvas}{%
  \hspace{.8\textwidth}\includegraphics[width=.2\paperwidth,height=\paperheight]{example-image-duck}%
}
\AtBeginSubsection[]{
  \begin{frame}<beamer>[label=sym]
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}
\subsection[problem when you can zip]{problem when you can zip}
\endgroup

\begin{frame}
  \frametitle{zipping solves everything}
  Lorem ipsum
\end{frame}

\subsection{1234}

\begin{frame}
  \frametitle{conclusion}
  \begin{itemize}
    \item headache ahead
    \item<2-> Bonus points for those who spotted the mistake on slide~\ref{sym}
  \end{itemize}
\end{frame}

\end{document}

答案2

这是一项临时提案。正如 Skillmon 指出的,其中有一个不必要的\expandafter

\documentclass{beamer}
\usepackage{graphicx}

\AtBeginSubsection[]
{
  \begin{frame}<beamer>{}
    \ifx\mylabel\empty
    \else
      \label{\mylabel}
    \fi  
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

\xdef\mylabel{\empty}
\begin{document}

\section{recap}
\subsection{what do we want}

\begin{frame}{what do we want}
  \begin{itemize}
      \item we want it all
  \end{itemize}
\end{frame}

\xdef\mylabel{sym}
\setbeamertemplate{background canvas}{%
  {~}\hspace{.8\textwidth}\includegraphics[width=.2\paperwidth,height=\paperheight]{./symmetry_breaking.png}
}


\subsection[problem when you can zip]{problem when you can zip}

\xdef\mylabel{\empty}
\beamertemplateshadingbackground{blue!01!white}{white}

\begin{frame}
  \frametitle{zipping solves everything}
  Lorem ipsum
\end{frame}

\subsection{1234}

\begin{frame}
  \frametitle{conclusion}
  \begin{itemize}
    \item headache ahead
    \item<2-> Bonus points for those who spotted the mistake on
    slide~\ref{sym}
  \end{itemize}
\end{frame}

\end{document}

答案3

添加一个命令,您可以选择标记添加\AtBeginSubsection到代码中的下一个子部分:

\documentclass{beamer}
\usepackage{graphicx}

\newif\ifLabelSubSec
\newcommand\LabelSubSec[1]
  {%
    \global\LabelSubSectrue
    \gdef\SubSecLabel{#1}%
  }

\AtBeginSubsection[]
{%
  \begin{frame}<beamer>{}
    \ifLabelSubSec
      \global\LabelSubSecfalse
      \label{\SubSecLabel}%
    \fi
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}%
}

\setcounter{secnumdepth}{2}

\begin{document}

\section{recap}
\subsection{what do we want}

\begin{frame}{what do we want}
  \begin{itemize}
      \item we want it all
  \end{itemize}
\end{frame}

\setbeamertemplate{background canvas}{%
  {~}\hspace{.8\textwidth}\includegraphics[width=.2\paperwidth,height=\paperheight]{example-image-duck}
}

\LabelSubSec{sym}
\subsection[problem when you can zip]{problem when you can zip}

\beamertemplateshadingbackground{blue!01!white}{white}

\begin{frame}
  \frametitle{zipping solves everything}
  Lorem ipsum
\end{frame}

\subsection{1234}

\begin{frame}
  \frametitle{conclusion}
  \begin{itemize}
    \item headache ahead
    \item<2-> Bonus points for those who spotted the mistake on slide~\ref{sym}
  \end{itemize}
\end{frame}

\end{document}

相关内容