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.

How to make multiline item label ?

Example

\documentclass[a4paper,10pt]{article}
\usepackage{lipsum}
\begin{document}
\begin{itemize}
\item[Great Item] \lipsum[1]
\end{itemize}
\end{document}

I would love to do

\item[Great \newline Item] \lipsum[1]

But I does not work.

Expected result - first lines of litem label and item content aligned:

Great   Lorem ipsum dolor sit amet,
Item    consectetuer adipiscing elit.
        Ut purus elit, ver...

To be more specific I use mydesc environment provided at http://tex.stackexchange.com/a/23569/7128 . I would love to make it work together. Above example is overslimplified. Here is more detailed :

\documentclass[a4paper,10pt]{article}
\usepackage{lipsum}
% mydesc thanks for http://tex.stackexchange.com/a/23569/7128
\newenvironment{mydesc}[1]
  {\list{}{\renewcommand\makelabel[1]{\it##1\hfil}%
     \settowidth\labelwidth{\makelabel{\it#1}}%
     \setlength\leftmargin{\dimexpr\labelwidth+\labelsep\relax}}}
  {\endlist}
\begin{document}
\begin{mydesc}{LongestItem}
\item[Great Item] \lipsum[1]
\end{mydesc}
\end{document}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

LaTeX offers a command \shortstack for this kind of thing, so your solution could look like this:

\item[\smash{\shortstack[l]{Great\\Item}}] \lipsum[1]

Unfortunately, \shortstack is bottom-aligned by default, so we have to hack a "top" variant:

\makeatletter
\gdef\tshortstack{\@ifnextchar[\@tshortstack{\@tshortstack[c]}}
\gdef\@tshortstack[#1]{%
  \leavevmode
  \vtop\bgroup
    \baselineskip-\p@\lineskip 3\p@
    \let\mb@l\hss\let\mb@r\hss
    \expandafter\let\csname mb@#1\endcsname\relax
    \let\\\@stackcr
    \@ishortstack}
\makeatother
\begin{document}
\begin{itemize}
\item[\smash{\tshortstack[l]{Great\\Item}}] \lipsum[1]
\end{itemize}

enter image description here

The code for \tshortstack was just copied from the respective code in the LaTeX sources. If you don't want to copy so much code, you can also use \patchcmd:

\documentclass[a4paper,10pt]{article}
\usepackage{lipsum}
\usepackage{etoolbox}
\makeatletter
\gdef\tshortstack{\@ifnextchar[\@tshortstack{\@tshortstack[c]}}
\let\@tshortstack\@shortstack
\patchcmd\@tshortstack\vbox\vtop{}{}
\makeatother
\begin{document}
\begin{itemize}
\item[\smash{\tshortstack[l]{Great\\Item}}] \lipsum[1]
\end{itemize}
\end{document}
share|improve this answer
1  
@GrzegorzWierzowiecki I forgot to copy \makeatletter in the first version of my code. Please try again. –  Stephan Lehmke Aug 27 '12 at 9:46
    
Now works - great, thanks ! :) –  Grzegorz Wierzowiecki Aug 27 '12 at 9:47

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.