1

Title describes my goal, so far the MWE:

\documentclass{article}
\usepackage{enumitem, lipsum}

\begin{document} \begin{description}[leftmargin=!, align=right, ] \item[label 0] \lipsum[75] \item[\begin{tabular}{c} label 1 1st line\ label 1 2nd line \end{tabular}] \lipsum[75]

\item[\smash{\begin{tabular}{c} label 2 1st line\ label 2 2nd line \end{tabular}}] \lipsum[75] \end{description}

\end{document}

\smash and tabular help me getting closer to the goal but still, the 1st line of list content align with the mid point of the label (not 1st line):

enter image description here

How do I align the 1st line of list content with 1st line of the label to have the following effect?

            labe 0     { content of label 0 }

1st line of labe 1 { content of label 1; content of label 1; 2nd line of labe 1 content of label 1; content of label 1; c ontent of label 1 }

Ideally the vertical spacing of label and content should matched, and this is why I also hope to eventually get rid of tabular since it adds extract space both vertically and horizontally.

Rahn
  • 498

2 Answers2

1

You may liked the following solution which not use tabular for formation of item labels:

\documentclass{article}
\usepackage{enumitem}
\SetLabelAlign{right}{\strut\smash{\parbox[t]\labelwidth{\raggedleft #1}}} % <--
\usepackage{lipsum}

\begin{document} \begin{description}[labelwidth=8em, align=right, leftmargin=!, ] \item[label 0] \lipsum[75] \item[label 1 1st line\ % <-- label 1 2nd line] \lipsum[75] % <--

\item[label 2 1st line\ label 2 2nd line] \lipsum[11] \end{description}

\end{document}

enter image description here

Edit: Used definition of right have sense and influence only in case if any of list is formatted with options:

[labelwidth=8em, % <---
 align=right,
 leftmargin=!,   % <---
 ]

however, you can limit \SetLabelAlign to some local group:

\documentclass{article}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{lipsum}

\begin{document} { % <-- start of local group \SetLabelAlign{right}{\strut\smash{\parbox[t]\labelwidth{\raggedleft #1}}} \begin{description}[labelwidth=8em, align=right, leftmargin=!, ] \item[label 0] \lipsum[75] \item[label 1 1st line\ label 1 2nd line] \lipsum[75]

\item[label 2 1st line\ label 2 2nd line] \lipsum[66] \end{description} } % <-- end of local group \begin{enumerate} \item[1] \lipsum[66] \item[22] \lipsum[66] \item[333] \lipsum[66] \end{enumerate}

\begin{description} \item[test] \lipsum[66] \item[longer item label] \lipsum[66] \end{description} \end{document}

enter image description here

Zarko
  • 296,517
  • Could you also provide the code to undo SetLabelAlign (set to default) afterwards? – Rahn Jan 26 '21 at 10:52
  • @Rahn, this definition not harm option align=right any of lists. It has influence only with option, where you determine label width and leftmargin, in your case: [labelwidth=8em, align=right, leftmargin=!, ]. Anyway, iy fill more comfortable, you can inclose redefinition of right in some local group. See edit in answer. – Zarko Jan 26 '21 at 11:19
0

A solution with stackengine:

\documentclass{article}
\usepackage{enumitem, lipsum}
\usepackage[usestackEOL]{stackengine}

\begin{document}

\begin{description}[leftmargin=!, align=right, ] \item[label 0] \lipsum[75] \item[\smash{\Longunderstack{ label 1 1st line\ label 1 2nd line}}] \lipsum[75]

\item[\smash{\Longunderstack{ label 2 1st line\ label 2 2nd line}}] \lipsum[75] \end{description}

\end{document}

enter image description here

Bernard
  • 271,350