4

I am trying to use the enumitem package to create the following

             Farmer: It is a hard day today. The sun is
                     burning and we still haven't brought
                     in all the crop.
 Farmer's Neighbour: Yes, it will be a long day!
             Farmer: ...

I want the label to be right aligned and the text to wrap at that point too.

I tried the following solution (\SetLabelAlign{parright}{\parbox[t]{\labelwidth}{\raggedleft#1}}, but then my label and text overlap.

\documentclass{article}
\usepackage{enumitem}
\SetLabelAlign{parright}{\parbox[t]{\labelwidth}{\raggedleft#1}}
\setlist[enumerate]{
  align=parright, 
  leftmargin=0pt, 
  labelindent=20pt,
  listparindent=40pt, 
  labelwidth=20pt, 
  itemindent=!
 }

\begin{document}
\begin{enumerate}[label=Farmer:]
  \item It is a hard day today. The sun is burning and we still haven't brought in all the crop.
\end{enumerate}
\begin{enumerate}[label=Farmer's Neigbour:]
   \item Yes, it will be a long day!
 \end{enumerate}
 \end{document}
Alan Munn
  • 218,180
Jo-
  • 221

1 Answers1

6

For a list-by-list basis, you can use the options below between [..]. Notice that calc package is required to measure the width of the widest label automatically. If you need the same settings for all description lists, use this command

\setlist[description]{style=multiline, labelwidth=\widthof{Farmer's Neigbour: },%
                    font=\normalfont, leftmargin=\labelwidth, align=right}

in preamble.

\documentclass{article}
\usepackage{enumitem}
\usepackage{calc}

\begin{document}

\begin{description}[style=multiline, labelwidth=\widthof{Farmer's Neigbour: },%
                    font=\normalfont, leftmargin=\labelwidth, align=right]
\item[Farmer:] It is a hard day today. The sun is burning and we still haven't brought in all the crop.
\item[Farmer's Neigbour:] Yes, it will be a long day!
\end{description}

\end{document}

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • If you want to keep the regular description list, you can define a new list, e.g. \newlist{dialogue}{description}{1} and then use \setlist[dialogue]{style=multiline, labelwidth=\widthof{Farmer's Neigbour: },font=\normalfont, leftmargin=\labelwidth, align=right} – Alan Munn Aug 08 '18 at 03:04
  • Is there a way to dynamically update `\widthof{Farmer's Neighbour:}? So the list can be reused? – Jo- Aug 08 '18 at 03:05
  • This will require more work, in such a case, a longtable or just a tabular may be preferred. – AboAmmar Aug 08 '18 at 03:10
  • 1
    @Jo- Not completely automatic, but if you define a new list, then for any particular instance of that environment you can just specify a new value for the labelwidth, e.g. \begin{dialogue}[labelwidth=\widthof{Farmer's son: }]. – Alan Munn Aug 08 '18 at 03:17