Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In my document I have a description environment. One of the titles in the description is too long to fit in one line and I want to break it. I know this is a bad styling but I can't think of any way to shorten it. I tried \\ and \newline and they didn't work. What else can I do?

I tried to use the mdwlist package. I added the following in the begining of my document:

\renewenvironment{description}{
  \begin{basedescript}{%
    \renewcommand{\makelabel}[1]{\bfseries##1}%
  }
}{%
  \desclabelstyle{\multilinelabel}

  \end{basedescript}%

}

but all I got is the same result.

I also tried this without any effect:

\renewenvironment{description}{
  \desclabelstyle{\multilinelabel}
  \begin{basedescript}{%
    \renewcommand{\makelabel}[1]{\bfseries##1}%
  }
}{%
  \end{basedescript}%
}

I can't use the \multilinelabel since the words in the label are too long, thus, I want to use \pushlabel. However, this doesn't work even in the example you given (probably, it doesn't know how to break lines). Is there any way to force break lines?

share|improve this question
    
\pushlabel moves the text following the label to the right but does not allow line break at the label. Have a look at the two suggestions at my answer below, that provides line break at the label. –  Schweinebacke Nov 20 '11 at 15:37
    
@Schweinebacke: This is what I did. Thanks. –  Yotam Nov 21 '11 at 8:17
add comment

3 Answers

up vote 3 down vote accepted

If your description items may be longer than a line I would suggest to use a paragraph or subparagraph instead:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}

\newcommand*{\mtol}{This is some more text than fit at ony line but only some
  and not a lot}

\begin{document}
\subparagraph{\mtol} \blindtext
\subparagraph{Or with less text} \blindtext
\subparagraph{\mtol} \blindtext
\subparagraph{\mtol} \blindtext

\end{document}

This may result in

result of the example

This may or may not be what you want. If you don't like the par indent before the label, simply replace \subparagraph by \paragraph.

Or you may define your own multi line description environment, e.g. using addmargin environment of KOMA-Script package scrextend:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{scrextend}

\newcommand*{\mtol}{This is some more text than fit at ony line but only some
  and not a lot}

\newenvironment{mldescription}{%
  \begin{addmargin}[2em]{1em}
    \setlength{\parindent}{-1em}%
    \newcommand*{\mlitem}[1]{\par\textbf{##1}\quad}\indent
}{%
  \end{addmargin}
  \medskip
}

\begin{document}
\blindtext
\begin{mldescription}
\mlitem{\mtol} \blindtext
\mlitem{Or with less text} \blindtext
\mlitem{\mtol} \blindtext
\mlitem{\mtol} \blindtext
\end{mldescription}
\blindtext

\end{document}

This would result in

result of mldescription list

That should almost be, what you want. If you want more or less indention or more or less hanging text, simply change the values of the addmargin environment or the \parindent.

And if you want additional vertical space between the items you may add this to the definition of the new environment too:

\newenvironment{mldescription}{%
  \begin{addmargin}[2em]{1em}
    \setlength{\parindent}{-1em}%
    \newcommand*{\mlitem}[1]{\par\medskip% vertical space
      \textbf{##1}\quad}\indent
}{%
  \end{addmargin}
  \bigskip% changed to have more vertical space than between items
}

same with vertical space

If you're already using a KOMA-Script class, you don't need to load package scrextend.

share|improve this answer
add comment

The package enumitem provide a style just for this:

\documentclass{article}

\usepackage{enumitem} % load this one

\usepackage{lipsum}
\newcommand*{\longtext}{This is some text that runs off the margin
  when used in a description label}

\newenvironment{longdescription}
  {\begin{description}[style=unboxed]}
  {\end{description}}

% Just to get dummy text
\usepackage{lipsum}
\newcommand*{\longtext}{This is some text that runs off the margin
  when used in a description label}

\begin{document}
\lipsum[2]

\begin{longdescription}
\item[\longtext] \lipsum*[3]
\item[Normal label] \lipsum*[4]
\end{longdescription}

\lipsum[2]

\end{document}

enter image description here

share|improve this answer
add comment

In such situations, where you need multi-line text, you could use \parbox, such as

\documentclass{article}
\begin{document}
\begin{description}
\item[\protect{\parbox[t]{1cm}{long\\label}}] text
\end{description}
\end{document}

description list with multi line label

Here I used the alignment parameter t in the optional argument for \parbox to get vertical alignment at the top line.

If would like to customize it further, have a look at the mdwlist package, which offers several different styles for description list labels, also for multi-line labels. It also solves the problem with multi-line labels combined with multi-line description.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{mdwlist}
\begin{document}
\begin{basedescript}{%
  \desclabelstyle{\multilinelabel}
  \desclabelwidth{2cm}}
\item[This is a pretty long text for a label] \blindtext
\item[more] text
\end{basedescript}
\end{document}

mdwlist multi-line label example

share|improve this answer
    
This does not work, if the you have more than one line of text after the \item argument (e.g. replace text by \blindtext using package blindtext). To make it work, you need the optional height argument of \parbox to fake height/depth. But this may be a problem while page break. –  Schweinebacke Nov 20 '11 at 10:20
    
Sure, with \parbox one might have to take more care, as in the case you mentioned, that's why I recommended mdwlist. Now I added an example for demonstration. –  Stefan Kottwitz Nov 20 '11 at 11:02
    
Nevertheless the mdwlist example is still a problem at page break. Simply add \blindtext[2]\par\vspace{2\baselineskip}\blindtext[3] before the baseddescript environment to see this. Users should know this. –  Schweinebacke Nov 20 '11 at 11:10
1  
Could be fixed with the needspace package, if the user insists on using a description list. Nevertheless, I answered the specific question how to get a line break in a description list, not by recommending something different nor treating cases the OP did not mention. But good that you point to possible problems one would might have to take care of. –  Stefan Kottwitz Nov 20 '11 at 11:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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