Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

I want my items in lists (enumerate, itemize and description) to be raggedright. So I use enumitem package to make things easier

\usepackage{enumitem}
\setlist[enumerate]{before = \raggedright}% In fact I use \RaggedRight from ragged2e package, but it doesn't matter (I think)

But then I found a problem: if the enumerate is in another paragraph it works great; but if it is in the same, the \raggedright applies to the paragraph too.

\documentclass{scrartcl}
\usepackage{enumitem}
\setlist[enumerate]{before=\raggedright}

\begin{document}
%   THIS WORKS
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\begin{enumerate}
    \item Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    \item Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{enumerate}

%   THIS DOESN'T
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\begin{enumerate}
    \item Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    \item Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{enumerate}
\end{document}

How can I solve this? Is this a bug?

enter image description here

EDIT:

After reading @egreg 's answer. I'm still not completely pleased because I get two different spacing if I compile this

\documentclass{scrartcl}
\usepackage{enumitem}
%\setlist[enumerate]{before=\csname par\endcsname\raggedright}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{enumerate}\raggedright
    \item Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{enumerate}
\end{document}

and this

\documentclass{scrartcl}
\usepackage{enumitem}
\setlist[enumerate]{before=\csname par\endcsname\raggedright}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{enumerate}%\raggedright
    \item Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\end{enumerate}
\end{document}

And I'm not totally convinced that the second one (egreg's one) is right (the space is larger).

share|improve this question

marked as duplicate by Kurt, zeroth, Claudio Fiandrino, Stephen, Martin Schröder Mar 24 '13 at 18:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
No difference for me: img542.imageshack.us/img542/9996/shutterseleo006.png –  Sigur Mar 24 '13 at 15:27
    
@Sigur Even with article? What's going on? I don't know why it shows that way to me. –  Manuel Mar 24 '13 at 15:29
    
Yes, the same: img824.imageshack.us/img824/7355/shutterseleo007.png –  Sigur Mar 24 '13 at 15:31
    
I get exactly the same output as Manuel. –  egreg Mar 24 '13 at 15:32
    
@Sigur, you don't have it \raggedright. I don't know what have you compiled (I didn't realized before). –  Manuel Mar 24 '13 at 15:33
show 9 more comments

1 Answer 1

up vote 5 down vote accepted

Here's a way to solve the issue, which is due to the fact that the second case doesn't end the previous paragraph when \begin{itemize} is performed, so the \raggedright code influences it:

\setlist[itemize]{before=\csname par\endcsname\raggedright,
  partopsep=0pt}

In this way we end the paragraph before starting the itemize list. The

\csname par\endcsname

trick is to avoid a spurious error message.

Alternative way. No before=\raggedright setting, but

\usepackage{etoolbox}
\AtBeginEnvironment{itemize}{\preto\item{\raggedright}}

Beware that this setting will be inherited by all lists nested to an itemize environment.

share|improve this answer
    
But don't I get the \parskip space before the list? –  Manuel Mar 24 '13 at 15:40
    
@Manuel Yes. But if you use a non zero parskip, you're doing bad typography. ;-) –  egreg Mar 24 '13 at 15:42
    
The option does not work for me! Strange. Maybe my package is out of date. –  Sigur Mar 24 '13 at 15:44
    
I use the default one, I think, (which I don't know how much space it is). But I'm (still) not convinced that before the enumerate there should be a \parskip. It continues the paragraph before, just in a more graphical way. See my edit, I explain my idea a little bit better. –  Manuel Mar 24 '13 at 16:15
    
That worked. By the way, do you think that this should be reported? If this is the expected way of working, I think it's wrong. –  Manuel Mar 25 '13 at 12:01
add comment

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