Text FormattingDescription-like environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
darktagnan
Posts: 2
Joined: Sat May 02, 2009 1:46 am

Description-like environment

Post by darktagnan »

Hello! I'm trying to do something like a description environment but with no indentation, minimmum width between lines and horizontally aligned lines of descriptions (apart from the labels) . Like this:

Code: Select all

Label1  Text which is at least two lines long. I mean bla bla bla bla
        bla bla bla bla bla bla bla bla bla bla.
Label2  And we go on with the same alignment.
I coded something that seems to do the task, but it is horribly messy and I'm sure I will have problems with it. The question is: can any of you think of a better solution?

My attemp in a minimal example:

Code: Select all

\documentclass[a4paper,11pt]{article}

\newlength{\gnat}\newlength{\gnatt}\newlength{\gnath}\newlength{\gnatw}\newlength{\gnatd}

\def\largo#1#2{\settowidth{\gnatt}{\textbf{#1} \ }\setlength{\gnat}{\linewidth}\addtolength{\gnat}{-1\gnatt}\begin{minipage}{\gnat}{#2}\end{minipage}}

\def\largoh#1#2{\settoheight{\gnath}{\largo{#1}{#2}}\settowidth{\gnatw}{\textbf{#1} \ }\parbox{\gnatw}{\textbf{#1} \ \vspace{\gnath}\vfill}\=\largo{#1}{#2}}

\def\largot#1#2#3{\settoheight{\gnath}{\largo{#1}{#3}}\settodepth{\gnatd}{\largo{#1}{#3}}\addtolength{\gnath}{\gnatd}\addtolength{\gnath}{-8pt}\settowidth{\gnatw}{\textbf{#1} \ }\parbox{\gnatw}{\textbf{#2}\vspace{\gnath}\vfill}\>\largo{#1}{#3}}

\begin{document}
Text which comes before the description. It has to be close to it and both should be horizontally aligned.
\begin{tabbing}
\largoh{Label1}{Text which is at least two lines long. I mean bla bla bla bla bla bla bla bla bla bla bla bla bla bla.}\\[4pt]
\largot{Label1}{Label2}{We go on doing these long descriptions like bla bla bla bla bla bla bla bla bla bla bla bla bla bla.}\\[4pt]
\largot{Label1}{Tiny}{We go on doing these long descriptions like bla bla bla bla bla bla bla bla bla bla bla bla bla bla.}
\end{tabbing}
Now the same as a normal description:\vspace{-4pt}
\begin{description}
\item[Label1]Text which is at least two lines long. I mean bla bla bla bla bla bla bla bla bla bla bla bla bla bla.\vspace{-10pt}
\item[Label2]Text which is at least two lines long. I mean bla bla bla bla bla bla bla bla bla bla bla bla bla bla.\vspace{-10pt}
\item[Tiny]Text which is at least two lines long. I mean bla bla bla bla bla bla bla bla bla bla bla bla bla bla.\vspace{-4pt}
\end{description}
It is not actually the same.
\end{document}
Thanks a lot! Best wishes

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
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Description-like environment

Post by Stefan Kottwitz »

Hi darktagnan,

welcome to the board!
You've posted a good minimal working example. Here's an example using expdlist:

Code: Select all

\documentclass[a4paper,11pt]{article}
\usepackage{expdlist}
\begin{document}
Text which comes before the description. It has to be close to
it and both should be horizontally aligned.
\begin{description}[\compact\setlabelphantom{Label2}]%
    \item[Label1] Text which is at least two lines long. I mean
        bla bla bla bla bla bla bla bla bla bla bla bla bla bla.
    \item[Label2] We go on doing these long descriptions
        like bla bla bla bla bla bla bla bla bla bla bla bla bla bla.
    \item[Tiny] We go on doing these long descriptions like bla bla
        bla bla bla bla bla bla bla bla bla bla bla bla.
\end{description}
\end{document}
If you liked it have a look at the expdlist documentation.

Stefan
LaTeX.org admin
darktagnan
Posts: 2
Joined: Sat May 02, 2009 1:46 am

Re: Description-like environment

Post by darktagnan »

Wow! I'm amazed! It's exactly what I meant! Thanks a lot for the package. You are great. It may seem a stupid thing but I am a kind of obsessed with typesetting and this is just beautiful. I'm happy. Have a great day!
Juan
PS: Reading the package's documentation convinced me that TeX knowledge is definitely valuable. Maybe in some time I'll study that and collaborate with the community. Excellent forum! Congratulations.
Post Reply