29

Which is the right way to do something like 'description' list but with customizable and fixed-width labels? I.e. something like this:

Label:         Text text text text text text
               text text text text.
Longer label:  Text text text text text text
               Text text text text.

The way I see it to use two-column table (first columt for labels and second column for descriptions), but this solution seems ugly. Is there any other way?

2

5 Answers 5

40

You can use the enumitem package to customize the description environment, e.g.

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{description}[leftmargin=8em,style=nextline]
  \item[Something] Text. More text.More text.More text. More text. More text. More text. More text. More text. More text. More text. More text. More text. 
  \item[Ought else] More text.
\end{description}
\end{document}

enter image description here

You can set this for all description environments (probably not desirable) with

\setlist[description]{leftmargin=8em,style=nextline}

or you can define your own list environment e.g.

\newlist{NewDesc}{description}{2}
\setlist[NewDesc]{leftmargin=8em,style=nextline}

and use as

\begin{NewDesc}
  \item[Something] Text. More text.More text.More text. More text. More text. More text. More text. More text. More text. More text. More text. More text. 
  \item[Ought else] More text.
\end{NewDesc}
1
  • 1
    Enumitem package works excellent for me.
    – Oleg
    Nov 6, 2011 at 9:31
11

The KOMA-Script classes and the scrextend package (part of KOMA-Script) provide the labeling list environment. It takes the length of the longest label as mandatory argument.

\documentclass{article}

\usepackage{scrextend}
\addtokomafont{labelinglabel}{\sffamily\bfseries}

\begin{document}

\begin{labeling}{Longer label\quad}
\item[Label] Some text.
\item[Longer label] Some text.
\end{labeling}

\end{document}

enter image description here

5

Another way, far less elegant to what enumitem is to use a tabular-related structure.

enter image description here

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\newcolumntype{L}{@{}>{\bfseries}p{8em}<{:}}% Item label
\newcolumntype{I}{X@{}}% Item contents
\noindent\begin{tabularx}{\textwidth}{LI}
  Label & \lipsum[1] \\
  Longer label & \lipsum[2]
\end{tabularx}
\end{document}

In the above example, tabularx was used to have a table with flexible columns to the maximum text block width (\textwidth). Additionally, the array package provides a means to insert code before/after column entries. This way it is possible to format the first column entries #1 as \bfseries#1: (automatically prepending a bold format and appending a colon :). Finally, the outer column spacing was removed using a @{} column specifier.

The drawbacks are:

  • The tabular does not flow across page breaks; and
  • It's interface is not as easy as list with special sequences required to distinguish item labels and contents (&) and "new items" (\\).

lipsum merely provided some dummy text.

3

This may be useful. If you don't use IEEEtran document class, you can use the IEEEtrantools package.

\documentclass{IEEEtran}
% \documentclass{article}
% \usepackage{IEEEtrantools}
\begin{document}
    \begin{IEEEdescription}[\IEEEsetlabelwidth{The longest Label}] % Longest label goes here as an argument!
        \item[Label] First item
        \item[Longer Label] Second item, text text text text text text. Text text text text text text text text text text text text!
        \item[The longest Label] Third item
    \end{IEEEdescription}
\end{document}
2

Another option, inspired by Torbjørn T.'s answer:

\documentclass{article}
\usepackage{enumitem}

\newlist{Description}{description}{3}
\setlist[Description]{style=nextline}
\SetEnumitemKey{margin}{leftmargin={\widthof{#1}+2em}}

\begin{document}

\begin{Description}[margin=longer label]
\item[label] Text. More text.More text.More text. More text. More text.   More text. More text. More text. More text. More text. More text. More text. 
\item[longer label] More text.
\end{Description}

\end{document}

You must log in to answer this question.

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