GeneralAlignment of Description List

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
spee
Posts: 4
Joined: Thu Jan 28, 2010 5:50 pm

Alignment of Description List

Post by spee »

I want to change the alignment of a description list so I get the following.

Code: Select all

Label is long   text 
lab2            blalballalaa
                possible second rule
label3          hello world
Guess it's a \renewcommand option, but can't find it.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Alignment of Description List

Post by gmedina »

Hi,

you can use some of the features provided by the enumitem package.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
spee
Posts: 4
Joined: Thu Jan 28, 2010 5:50 pm

Re: Alignment of Description List

Post by spee »

Probably, but I prefer not adding an package (if possible).
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Alignment of Description List

Post by gmedina »

Hi,

you can use a list environment to define a new environment that behaves as you describe. Take a look at the following example code (a slight modification of an example given in The LaTeX Companion):

Code: Select all

\documentclass{article} 

\newenvironment{mydescription}[1]
  {\begin{list}{}%
   {\renewcommand\makelabel[1]{##1:\hfill}%
   \settowidth\labelwidth{\makelabel{#1}}%
   \setlength\leftmargin{\labelwidth}
   \addtolength\leftmargin{\labelsep}}}
  {\end{list}}

\begin{document}

\begin{mydescription}{longest label}
  \item[label1] text text text.
  \item[longest label] text text text.
  \item[lab2] text text text text text text text text text text text text text text text text text 
    text text text text text text text text text text text text text text.
\end{mydescription}

\end{document}
The argument of the mydescription environment specifies the width of the label field (in your case, it corresponds to the widest entry).
1,1,2,3,5,8,13,21,34,55,89,144,233,...
hkarl
Posts: 3
Joined: Mon Jan 09, 2012 7:28 pm

Re: Alignment of Description List

Post by hkarl »

Hi,

I've been trying to replicate this very behavior using enumitem (version 3.5.2), but abysmally. (Very confused by the enumitem manual).

This should be possible, shouldn't it?


Thanks a lot,

Holger
(Too ashamed to post my own trials, non worked...)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Alignment of Description List

Post by Stefan Kottwitz »

Hi Holger,

I guess it's easier with the mdwlist package.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment of Description List

Post by localghost »

Stefan_K wrote:[…] I guess it's easier with the mdwlist package. […]
The enumitem package should be preferred as mentioned in the CTAN entry of mdwlist.


Thorsten
Post Reply