19

I have quite a lot of description environments in Beamer that are having both long and short items, leading to an output like

veryverylongitem description 1
    shortitem description 2

which is not really great.

So I'm trying to put labels and descriptions on different lines, in something like

veryverylongitem
            description 1
shortitem
            description 2

I've tried two things for that:

\let\origdescription\description
\renewenvironment{description}{
\setlength{\leftmargini}{0em}
\origdescription
\setlength{\itemindent}{0em}
\setlength{\labelsep}{\textwidth}
}
{\endlist}

which seem to do what I'd like, except that things are completely glitchy when using two nested description environment

On another hand, puting something like

\begin{description}
\item[veryveryveryverylongitem]\hfill\\
     description 1
\item[shortitem]\hfill\\
     description 2
\end{description}

will do the job perfectly, except that I can't find a way to do renew the item command so that the hfill would applied document-wide.

Is there other way to deal with long description, or have I done something wrong in the two solutions ?

2 Answers 2

38

Using the enumitem package with beamer is not a good idea; for example, just by loading enumitem, the default beamer font and color specifications for description are lost; moreover \setbeamercolor and \setbeamerfont will have no effect on description item; even worst, the enumitem package will also interfere with the beamer layout for itemize and enumerate; in fact, it will produce errors for the enumerate environment (See example at the bottom).

In the following example I defined a Ldescription environment based on the beamer definition of standard description; since the new definition follows the "beamer way", it will behave as expected (it's overaly aware, for exampe, and respects the color and font templates) and will give you the desired layout (feel free to adjust the lengths according to your needs):

\documentclass{beamer}
\usepackage{lipsum}

\makeatletter
\def\Ldescription{%
  \@ifnextchar[{\beamer@testforospec}{\beamer@descdefault\beamer@descriptionwidth\@@Ldescription}%
}

\def\beamer@testforospec[{\@ifnextchar<{\beamer@scandefaultospec[}{\@Ldescription[}}%

\def\beamer@scandefaultospec[#1]{\def\beamer@defaultospec{#1}\Ldescription}

\def\@Ldescription[#1]{%
\setbox\beamer@tempbox=\hbox{\def\insertdescriptionitem{#1}
  \usebeamertemplate**{description item}}%
\beamer@descdefault\wd\beamer@tempbox\@@description%
}%

\def\@@Ldescription{%
  \beamer@descdefault35pt%
  \list
  {}
  {\labelwidth\beamer@descdefault\leftmargin2.8em\let\makelabel\beamer@Ldescriptionitem}%
  \beamer@cramped%
  \raggedright
  \beamer@firstlineitemizeunskip%
}

\def\endLdescription{\ifhmode\unskip\fi\endlist}
\long\def\beamer@Ldescriptionitem#1{%
  \def\insertdescriptionitem{#1}%
  \hspace\labelsep{\parbox[b]{\dimexpr\textwidth-\labelsep\relax}{%
        \usebeamertemplate**{description item}%
    }}}
\makeatother

\begin{document}

\begin{frame}
\begin{Ldescription}
\item<1->[very very very very long item] \lipsum[2]
\item<2,4>[short titem] description 2
\item<3->[another very very very very long item] description 3
\item<4->[short item] description 4
\end{Ldescription}
\end{frame}

\end{document}

An image of the fourth frame:

enter image description here

Why enumitem shouln't be used with beamer

Processing the following code:

\documentclass{beamer}
%\usepackage{enumitem}

\setbeamercolor{description item}{fg=olive!80!black}
\setbeamerfont{description item}{size=\footnotesize}

\begin{document}

\begin{frame}
\begin{description}
\item[item] description
\end{description}
\begin{itemize}
\item description
\end{itemize}
\end{frame}

\end{document}

produces the following (expected) output:

enter image description here

Now uncomment-out the line loading enumitem. reprocess and now you'll get the following undesired result:

enter image description here

Now, try this simple document:

\documentclass{beamer}
\usepackage{enumitem}

\begin{document}

\begin{frame}
\begin{enumerate}
\item test
\end{enumerate}
\end{frame}

\end{document}

and you'll receive:

! TeX capacity exceeded, sorry [grouping levels=255].
\labelenumi ->{
               \labelenumi }
l.10 \end{frame}
                
!  ==> Fatal error occurred, no output PDF file produced!

The moral is clear: enumitem and beamera are incompatible. Perhaps using the loadonly package option to create own lists could be safe:

\usepackage[loadonly]{enumitem}
6
  • @cyberSingularity No problem; in fact, I appreciate your comment; I will take a closer look (I only used the 1pt as a quick dirty workaround) and let you know when I find a satisfactory solution. Oct 12, 2012 at 14:03
  • @cyberSingularity I updated my answer; I hope this time the overfull boxes disappear. Please let me know if the new version works as expected. Oct 12, 2012 at 18:23
  • They do indeed disappear. Am I right in thinking that the main change is the \beamer@descdefault value? Oct 12, 2012 at 20:07
  • @cyberSingularity yes, you are right. Oct 12, 2012 at 20:08
  • Sorry to be a pain, I have posted a follow-up question at tex.stackexchange.com/q/76481/17427 and will delete my comments from here. Thanks! Oct 12, 2012 at 21:02
5

You can use the great enumitem package for this. It's already defined as a style under the descriptions class with nextline

\documentclass{beamer}
\usepackage{enumitem}
\begin{document}
\begin{frame}
\begin{description}[style=nextline]
\item<1->[veryveryveryverylongitem] description 1
\item<2-3>[shortitem] description 2
\item<3->[shortitem2] description 3
\item<4->[shortitem3] description 4
\end{description}
\end{frame}
\end{document}

enter image description here

For the overlay specification declaration one can use

\documentclass{beamer}
\usepackage{enumitem}
\begin{document}
\begin{frame}
\beamerdefaultoverlayspecification{<+->}
\begin{description}[style=nextline]
\item[veryveryveryverylongitem] description 1
\item[shortitem] description 2
\item[shortitem] description 2
\item[shortitem] description 2
\end{description}
\beamerdefaultoverlayspecification{}
\end{frame}
\begin{frame}[fragile]
\begin{description}[style=nextline]
\item[Any overlay?] No overlay!
\item[Yes] I see them all...
\item[Can make the command] {\verb|\beamerdefaultoverlayspecification{<+->}|}
\item[something] shorter
\end{description}           
\end{frame}
\end{document}

thanks to Marco Daniel, enumitem seems to be not that innocent to use in beamer. Also cmhughes' comment can be another option.

7
  • 1
    This solution isn't well. enumitem destroys the overlay specification of beamer. (Sorry) Apr 17, 2012 at 14:44
  • @MarcoDaniel No problem at all. I tried with a few and it works as usual (added a few in the example). Care to expand on that?
    – percusse
    Apr 17, 2012 at 14:46
  • 2
    you can use \usepackage[loadonly]{enumitem} and then create your own list- all of the existing lists (itemize, enumerate, description) are left alone
    – cmhughes
    Apr 17, 2012 at 14:57
  • 2
    Just loading enumitem will change the layout for the description environment defined by beamer (for example, it annihilates the color specifications of the desciption items). Apr 17, 2012 at 18:16

You must log in to answer this question.

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