2

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}
  • 2
    Why are you using an enumerate list when you want a description type list? – Alan Munn Aug 8 '18 at 2:36
  • Just try align=left, It should work. – javadr Aug 8 '18 at 2:41
3

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

  • 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 8 '18 at 3:04
  • Is there a way to dynamically update `\widthof{Farmer's Neighbour:}? So the list can be reused? – Jo- Aug 8 '18 at 3:05
  • This will require more work, in such a case, a longtable or just a tabular may be preferred. – AboAmmar Aug 8 '18 at 3: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 8 '18 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.