3

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 https://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 https://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}

1 Answers1

3

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}
  • 1
    @GrzegorzWierzowiecki I forgot to copy \makeatletter in the first version of my code. Please try again. – Stephan Lehmke Aug 27 '12 at 09:46
  • Dang it, the results (at least in my case) look God awful. I decide to move part of the item's label to its description as well as (for a different item) just to split it into two items. – rbaleksandar Mar 14 '17 at 19:43