7

My thesis contains many description environments. After showing it to my supervisor, he complained about the missing separation between the items titles and descriptions. I tried to redefine the \item command, to change all description environments at once, without changing every \item manually.

While my approach works for simple items (the first one), it fails for items that contain multiple paragraphs of text in the description (like the second one).

\documentclass{book}                                                                

\let\olddescription\description
\def\description{%
  \olddescription \let\olditem\item%
  \def\item[##1]##2{\olditem[##1]{\hfill \\##2}}}

\begin{document}
\begin{description}
\item[The First Item]{This text describes the first item.}
\item[The Second Item]{This text describes the second item.
Contrary to the description of the first item, it is quite a bit longer.

Additionally, it consists of multiple paragraphs, which causes problems
with redefining the item command.}
\end{description}
\end{document}

On compiling with pdflatex, the following error message appears:

Runaway argument?                           
{This text describes the second item. Contrary to the description of \ETC.
! Paragraph ended before \item was complete.
<to be read again>
                   \par
l.14

?
! Extra }, or forgotten \endgroup.
l.15 ...roblems with redefining the item command.}

?

If I remove the second item, it works. Is there a way to fix my \item command?


I know that I can just redefine the descriptionlabel command like this:

\let\olddescriptionlabel\descriptionlabel
\renewcommand*\descriptionlabel[1]{\olddescriptionlabel{#1:}}

But this does unfortunately not work for the line break I tried to add after the title using the code I found at http://en.wikibooks.org/wiki/LaTeX/List_Structures#Description.

  • What do you want to change? How should it look like? – Sigur Feb 26 '15 at 17:03
  • 3
    Commands defined with \def are not allowed to have \par in the replacement text. You need to use \long\def for that. – Henri Menke Feb 26 '15 at 17:04
7

In his answer, egreg has explained the problems with your current definition and a way to ammend it. However, I'd suggest you to use the nextline style for desciption offered by the enumitem package:

    \documentclass{book}                                                                
\usepackage{enumitem}

\setlist[description]{style=nextline}

\begin{document}
\begin{description}
\item[The First Item]
This text describes the first item.
\item[The Second Item]
This text describes the second item.
Contrary to the description of the first item, it is quite a bit longer.

Additionally, it consists of multiple paragraphs, and doesn't cause problems
since we didn't redefine the item command.
\end{description}
\end{document}

enter image description here

  • \LetLtxMacro is not needed here. – egreg Feb 26 '15 at 18:06
  • While trying to get it done by changing the \item command I totally overlooked this option of enumitem -.- – Roland Schwarzkopf Feb 27 '15 at 8:47
3

Your approach is faulty where you redefine \item with two arguments; the original \item has only one (at least for description):

\documentclass{book}

\expandafter\def\expandafter\description\expandafter{%
  \description \let\olditem\item
  \def\item[##1]{\olditem[##1]\mbox{}\\}}

\begin{document}
\begin{description}
\item[The First Item] This text describes the first item.
\item[The Second Item]This text describes the second item.
Contrary to the description of the first item, it is quite a bit longer.

Additionally, it consists of multiple paragraphs, which causes problems
with redefining the item command.
\end{description}
\end{document}

The braces you already have in your code will do nothing, so it's not really necessary to remove them.

enter image description here

Your code will work if you say \long\def\item[##1]##2{...} so as to allow for \par tokens in the second argument.

Of course the approach with enumitem is better.

  • I really like that solution, because it works without using yet another package. Unfortunately, it seams to break the \blindlist command of the blindtext package, that I use in some of the unfinished chapters, so I chose the solution of Gonzalo. – Roland Schwarzkopf Feb 27 '15 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.