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 Answer 1

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}
2
  • 1
    @GrzegorzWierzowiecki I forgot to copy \makeatletter in the first version of my code. Please try again. Aug 27, 2012 at 9: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. Mar 14, 2017 at 19:43

You must log in to answer this question.

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