3

I find myself using more and more using the following overlay specification for the description environment.

 The Animal Kingdom
 \begin{description}
   \item[Gnus]   \uncover<+->{these are large cow-like animals}
   \item[Gnats]  \uncover<+->{much smaller than gnus}
 \end{description}

The rationale is simple. I would like my audience to see that there two (and only two) animals in my animal kingdom. I would also like to see the names of these two. Then, I can go on elaborating, first on Gnus and then on Gnats.

I would be nice to write this without having to repeat the overlay specification after each label, e.g., as in

 \begin{description}[itemuncover<+->]
   \item[Gnus]  these are large cow-like animals
   \item[Gnats] much smaller than gnus
 \end{description}

which would expand to

 \begin{description}
   \item[Gnus]  \begin{uncoverenv}<+->
     these are large cow-like animals
    \end{uncoverenv}
   \item[Gnats] \begin{uncoverenv}<+->
       much smaller than gnus
    \end{uncoverenv}
 \end{description}
4
  • Please post a complete MWE rather than mere fragments of code as an MWE is much more useful.
    – cfr
    Commented Aug 23, 2014 at 21:48
  • 1
    In addition to my answer below: your code using \uncover... does not produce the result you described for me.
    – greyshade
    Commented Aug 24, 2014 at 9:54
  • You are right. I checked! Not sure if it is a bug, or the specification for the \uncoverenv are beyond my understanding.
    – Yossi Gil
    Commented Aug 24, 2014 at 14:16
  • My question seems to be a duplicate of tex.stackexchange.com/questions/154320/…
    – Yossi Gil
    Commented Sep 12, 2014 at 5:44

2 Answers 2

3
+50

The following should do what you required - i.e. show all labels right away, but uncover the descriptions one by one.

\documentclass{beamer}

\newcounter{curItem}
\newenvironment{descriptions}[1]{%
    \setcounter{curItem}{#1}
    \let\olditem\item%
    \renewcommand\item[2]{%
        \stepcounter{curItem}
        \olditem[##1] \mbox{}\visible<\value{curItem}->{##2}%
    }%
    \begin{description}%
}{%
    \end{description}%
}

\begin{document}

\begin{frame}{The Animal Kingdom}
    \begin{descriptions}{1}
        \item{Gnus}{these are large cow-like animals}
        \item{Gnats}{much smaller than gnus}
        \item{Gants}{them}
    \end{descriptions}
\end{frame}
\end{document}

This is how it works: We define a new environment descriptions within which a normal description is used with items that have their visibility controlled automatically by a \visible<#->. The new environment takes one argument which allows to define whether the first description is uncovered immediately or not (i.e. setting the argument to 0 or 1).* Within the new environment \item is redefined to take two arguments, the first being the label, the second the description. The new definition of \item automatically steps a counter which it then uses to control the visibility.

*Note: this argument also allows adapting the environment in the case there's other things on the slide being done with overlays. E.g. consider this:

\begin{frame}{The Animal Kingdom}
\only<1-2>{The more complex case of introducing the animal kingdom:}
\only<3->{They are described like this:}
\visible<2->{%
    \begin{descriptions}{3}
        \item{Gnus}{these are large cow-like animals}
        \item{Gnats}{much smaller than gnus}
        \item{Gants}{them}
    \end{descriptions}
}
\visible<2>{are the animals in the kingdom.}
\end{frame}
3
  • some inspiration (the use of \mbox) came from here, some more from my answer here.
    – greyshade
    Commented Aug 24, 2014 at 10:04
  • Any chance of making this cleaner, i.g., without wrapping the item's content in curly brackets.
    – Yossi Gil
    Commented Aug 24, 2014 at 14:21
  • @YossiGil none that would immediately come to mind - I'm open to suggestions if anyone has any?
    – greyshade
    Commented Aug 24, 2014 at 18:56
3

I came up with several tricks. However I'm not sure if they are robust enough. It all depends on your documents.

Firstly let me start with a very very simple example:

\documentclass{beamer}
\begin{document}
\begin{frame}{BEFORE}\only<+>{}
    \begin{description}[<+->]
        \item[A] aa aa aa aa aa aa aa aa
        \item[BB] bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
        \item[CCC] cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc
        \item[DDDD] dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd
    \end{description}
\end{frame}

It has an intermediate slide:

The first trick, as greyshade just did, is to declare your own \item command with two arguments. By doing so you can do almost everything since you catch the second argument. For example in my own version:

\newcommand\jtem[2][{}]{\only<-.>{\item[#1]{\color{white}#2}}\only<+->{\item[#1]{#2}}}
\begin{frame}{AFTER: j}\only<+>{}
    \begin{description}
        \jtem[A] {aa aa aa aa aa aa aa aa}
        \jtem[BB] {bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb}
        \jtem[CCC] {cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc}
        \jtem[DDDD] {dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd}
    \end{description}
\end{frame}

Notice that the separated \only<-.>{} and \only<+->{} allow the names shown in different formats before/after their descriptions appear.

Things become complicated if we want our \item assuming the same syntax as usual. The second trick is to typeset the name-part and the description-part alternatively. As follows:

\newcommand\ktem[1][]{\item<*>[#1]\item<uncover@+->}
\begin{frame}{AFTER: k}\only<+>{}
    \begin{description}
        \ktem[A] aa aa aa aa aa aa aa aa
        \ktem[BB] bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
        \ktem[CCC] cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc
        \ktem[DDDD] dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd
    \end{description}
\end{frame}

Then we will have a sparser slide:

There is a trivial way to fix it:

\newcommand\ltem[1][]{\item<*>[#1]\item<uncover@+->\vspace*{-16.6pt}}
\begin{frame}{AFTER: l}\only<+>{}
    \begin{description}
        \ltem[A] aa aa aa aa aa aa aa aa
        \ltem[BB] bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
        \ltem[CCC] cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc
        \ltem[DDDD] dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd
    \end{description}
\end{frame}

Here 16.6 is the magic number. This trick fails for different font size, different line skip, or any other reason making lines taller. (In this case, however, it looks fine.)

On the other hand if you do not have multiline description-part, simply copy the first trick:

\newcommand\mtem[1][{}]{\item<only@-.>[#1]\item<only@+->[#1]}
\begin{frame}{AFTER: m}\only<+>{}
    \begin{description}
        \mtem[A] aa aa aa aa aa aa aa aa
        \mtem[BB] bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
        \mtem[CCC] cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc
        \mtem[DDDD] dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd
    \end{description}
\end{frame}

Nevertheless there could be some shift if the description-part is taller.

The third trick deals with colors. The point is to change the color dynamically.

\newcommand\ntem[1][{}]{\item[#1]\only<-+>{\color{white}}}
\begin{frame}{AFTER: n}
    \begin{description}
        \ntem[A] aa aa aa aa aa aa aa aa
        \ntem[BB] bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
        \ntem[CCC] cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc
        \ntem[DDDD] dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd
    \end{description}\only<+>{}
\end{frame}

It fails, certainly, if you include any color-command between your words such as \alert or if the background is not white.

Similarly, we may also deal with opacities.

\newcommand\otem[1][{}]{\item[\pgfsetfillopacity{1}#1\only<-+>{\pgfsetfillopacity{0}}]}
\begin{frame}{AFTER: o}
    \begin{description}
        \otem[A] aa aa aa aa aa aa aa aa
        \otem[BB] bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
        \otem[CCC] cccccc cccccc cccccc cccccc cccccc cccccc cccccc cccccc
        \otem[DDDD] dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd dddddddd
    \end{description}\only<+>{}
\end{frame}

This is the most robust one since multiline, tall lines, and colors are harmless. The only drawback is that it may conflict with beamer's own transparency-effect, e.g. section 17.6.

Last but not the least:

\end{document}

You must log in to answer this question.

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