Where can I find the definition of the description environment available in beamer
? I'd like to replicate it for my own needs in an article-oriented document. I'm interested in its right-left alignment features:
beamerdescriptionlists
Where can I find the definition of the description environment available in beamer
? I'd like to replicate it for my own needs in an article-oriented document. I'm interested in its right-left alignment features:
To define the new environment just call the original one in it as last and first thing of the 'begin' and 'end' part, respectively. You can place your own redefinition before that. They will be local to this environment.
Note that the hash (#
) in macro arguments like #1
must be doubled in this case (##1
) to differ them for potential arguments of the environment.
\documentclass{article}
\newenvironment{mydescription}{%
\renewcommand\descriptionlabel[1]{\hspace{\labelsep}\textbf{(##1)}}
\begin{description}%
}{%
\end{description}%
}
\begin{document}
\begin{mydescription}
\item[First] Test
\item[Second] Test
\end{mydescription}
\begin{description}
\item[First] Test
\item[Second] Test
\end{description}
\end{document}
You can also improve this a little and write:
\newcommand\mydescriptionlabel[1]{\hspace{\labelsep}\textbf{(#1)}}
\newenvironment{mydescription}{%
\let\descriptionlabel\mydescriptionlabel
\description
}{%
\enddescription
}
This defines the custom macro outside of the environment so that the hashes aren't a problem which is important in more complex macros. The definition can then be copied using the \let
macro.
The internal environment is written into the plain form \description
... \enddescription
instead of \begin{description}
... \end{description}
to avoid confusing error messages when \end{mydescription}
is missing. In this case the last \begin
would be the one of the internal macro and its name would be printed in the error message instead of the one written in the source file. This isn't a problem for your own small environments, but important if they are used by other people.
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:
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:
Now uncomment-out the line loading enumitem
. reprocess and now you'll get the following undesired result:
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 beamer
a are incompatible. Perhaps using the loadonly
package option to create own lists could be safe:
\usepackage[loadonly]{enumitem}
Best Answer
I recommend using the
enumitem
package which allows customizing list environments such asdescription
. If you would edit your question specifying what's exactly desired, you could get an example.The
mdwlist
package is an alternative focussing on description lists.Here's a solution without these packages for right aligned description labels: