我如何使用不同的 Beamer 模板进行嵌套描述

我如何使用不同的 Beamer 模板进行嵌套描述

我如何使用不同的description itembeamer 模板进行嵌套描述?

我有一种特定的描述,称之为funnys,它们可能嵌套在幻灯片上,也可能嵌套在幻灯片中。我已经设置了 ,\defbeamertemplate{description item}但这用于描述环境本身,以及所有嵌套的描述!这不是我想要的。我希望嵌套的描述像往常一样排版。

下面的 MWE 演示了这种情况:前几帧演示了工作嵌套。然而,在最后一帧中,项目hannahjoe应该使用 的样式description,而不是环境的样式 funnys

\documentclass{beamer}

\defbeamertemplate{description item}{funny}{%
  \insertdescriptionitem \(\rightarrow\)\kern-0.3em%
}

\setbeamercolor{funnys}{bg=blue!5!white}
\newenvironment{funnys}{
  \par
  \vspace{0.3em}
  \begin{minipage}{\linewidth}%
    \begin{beamercolorbox}[wd=\linewidth,rounded=true,sep=-1em]{funnys}%
      \setbeamertemplate{description item}[funny]%
      \setbeamersize{description width=0.5ex}
      \begin{description}%
}{%
      \end{description}%
      \vspace{0.7em}
    \end{beamercolorbox}%
  \end{minipage}
  \par
  \vspace{0.5em}
}



\begin{document}

\begin{frame}{Good: /funnys}
  \begin{funnys}
  \item[alec] adsda fdj gfg fdg fdgsdf
  \item[barbara] djfb fgf dsda fdgsfdgf
  \end{funnys}
\end{frame}

\begin{frame}{Good: /itemize/funnys}
  \begin{itemize}
  \item fjkfkg g fdj sfdgfd
    \begin{funnys}
    \item[cohen] adsda fdj gfg fdg fdgsdf
    \item[dora] djfb fgf dsda fdgsfdgf
    \end{funnys}
  \item dslfjsdfgsjfs
  \end{itemize}
\end{frame}

\begin{frame}{Good: /description/funnys}
  \begin{description}[qwert]
  \item[qwert] fjkfkg g fdj sfdgfd
    \begin{funnys}
    \item[ethan] adsda fdj gfg fdg fdgsdf
    \item[fabrice] djfb fgf dsda fdgsfdgf
    \end{funnys}
  \item[yuiop] dslfjsdfgsjfs
  \end{description}
\end{frame}

\begin{frame}{Bad: /funnys/description}
  \begin{funnys}
  \item[greg] fjkfkg g fdj sfdgfd
    \begin{description}[hannah]
    \item[hannah] adsda fdj gfg fdg fdgsdf
    \item[joe] djfb fgf dsda fdgsfdgf
    \end{description}
  \item[karla] dslfjsdfgsjfs
  \end{funnys}

  Note that hannah and joe are items of a description, not of a
  funnys, so the template used is not what I had expected.

\end{frame}
\end{document}

答案1

这是一个选择;想法是使用:

\usepackage{etoolbox}
\AtBeginEnvironment{description}{\setbeamertemplate{description item}[default]}

并推迟

\setbeamertemplate{description item}[funny]

成为里面description定义中使用的。funnys完整的例子:

\documentclass{beamer}
\usepackage{etoolbox}

\AtBeginEnvironment{description}{\setbeamertemplate{description item}[default]}

\defbeamertemplate{description item}{funny}{%
  \insertdescriptionitem \(\rightarrow\)\kern-0.3em%
}

\setbeamercolor{funnys}{bg=blue!5!white}
\newenvironment{funnys}{
  \par
  \vspace{0.3em}
  \begin{minipage}{\linewidth}%
    \begin{beamercolorbox}[wd=\linewidth,rounded=true,sep=-1em]{funnys}%
      \setbeamersize{description width=0.5ex}
      \begin{description}%
      \setbeamertemplate{description item}[funny]%
}{%
      \end{description}%
      \vspace{0.7em}
    \end{beamercolorbox}%
  \end{minipage}
  \par
  \vspace{0.5em}
}



\begin{document}

\begin{frame}{Good: /funnys}
  \begin{funnys}
  \item[alec] adsda fdj gfg fdg fdgsdf
  \item[barbara] djfb fgf dsda fdgsfdgf
  \end{funnys}
\end{frame}

\begin{frame}{Good: /itemize/funnys}
  \begin{itemize}
  \item fjkfkg g fdj sfdgfd
    \begin{funnys}
    \item[cohen] adsda fdj gfg fdg fdgsdf
    \item[dora] djfb fgf dsda fdgsfdgf
    \end{funnys}
  \item dslfjsdfgsjfs
  \end{itemize}
\end{frame}

\begin{frame}{Good: /description/funnys}
  \begin{description}[qwert]
  \item[qwert] fjkfkg g fdj sfdgfd
    \begin{funnys}
    \item[ethan] adsda fdj gfg fdg fdgsdf
    \item[fabrice] djfb fgf dsda fdgsfdgf
    \end{funnys}
  \item[yuiop] dslfjsdfgsjfs
  \end{description}
\end{frame}

\begin{frame}{Good: /funnys/description}
  \begin{funnys}
  \item[greg] fjkfkg g fdj sfdgfd
    \begin{description}[hannah]
    \item[hannah] adsda fdj gfg fdg fdgsdf
    \item[joe] djfb fgf dsda fdgsfdgf
    \end{description}
  \item[karla] dslfjsdfgsjfs
  \end{funnys}

  Note that hannah and joe are items of a description, not of a
  funnys, so the template used is now what I had expected.
\end{frame}

\end{document}

结果:

在此处输入图片描述

相关内容