2

How can I use a different description item beamer template for nested descriptions?

I have a certain kind of descriptions, call them funnys, which may appear nested on slides, and may be nested themselves. I have set up a \defbeamertemplate{description item} but this is used for the description environment itself, plus all nested descriptions! This is not what I want. I want nested descriptions to be typeset as usual.

The MWE below demonstrares the case: The first frames demonstrate working nesting. On the last frame, however, the items hannah and joe should use the style of a description, not the style of a funnys environment.

\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 Answer 1

1

Here's one option; the idea is to use:

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

and to postpone

\setbeamertemplate{description item}[funny]

to be inside the description used in the definition of funnys. A complete example:

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

The result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .