5

How to have the full content of an enumerate item to start on a new line below the item label and number, and aligned to the left margin of the document ?

This question is closely related to this other question Forcing new line after item number in enumerate environment. However the solution provided only adjust the first line to the left margin, not the full content of the item.

I use the enumitem package.

Actual code:

\documentclass{article}  
\usepackage{enumitem}   

\setlength\parindent{0pt}

\makeatletter   
\def\itemq{\@ifnextchar[ \@itemq{\@noitemargtrue\@itemq[\@itemlabel]}}
\def\@itemq[#1]{\item[#1]\mbox{}\\\hspace*{\dimexpr-\labelwidth-\labelsep}}  
\makeatother 

\begin{document}

Nunc convallis tincidunt scelerisque. Praesent ac mattis ligula, dictum 
condimentum enim. Donec convallis id lorem vel lobortis. Duis dapibus metus ut
 risus egestas, in lobortis elit ultricies. Nam eu odio aliquam, ullamcorper
 quam sed, placerat massa.

\begin{enumerate}[align=left,label=\textbf{Question \arabic*},leftmargin=!]
\itemq Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan
 pulvinar magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed
 dictum. Nulla suscipit leo et luctus facilisis. Vivamus a lorem at libero 
elementum blandit eu quis diam. Fusce mollis lorem a diam consequat, non 
fermentum massa auctor.
\itemq Vivamus fringilla eget nisl at mattis. Sed commodo iaculis est,
 adipiscing pretium magna adipiscing eget. Donec sed ante at massa tincidunt 
porttitor vitae vel lectus. Sed facilisis feugiat felis, ultricies aliquam ante
 iaculis et. Suspendisse fringilla, purus nec convallis cursus, nunc lectus
 pharetra ipsum, nec hendrerit sem nunc eu nulla. Nam neque magna, faucibus
 vitae ante nec, hendrerit bibendum nunc.
\end{enumerate}

\end{document}

The desired output is like that:

\documentclass{article}

\setlength\parindent{0pt}

\begin{document}

Nunc convallis tincidunt scelerisque. Praesent ac mattis ligula, dictum 
condimentum enim. Donec convallis id lorem vel lobortis. Duis dapibus metus ut
 risus egestas, in lobortis elit ultricies. Nam eu odio aliquam, ullamcorper 
quam sed, placerat massa.

\medskip\textbf{Question 1}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan pulvinar
 magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed dictum.
 Nulla suscipit leo et luctus facilisis. Vivamus a lorem at libero elementum 
blandit eu quis diam. Fusce mollis lorem a diam consequat, non fermentum massa
 auctor.

\medskip\textbf{Question 2}

Vivamus fringilla eget nisl at mattis. Sed commodo iaculis est, adipiscing
 pretium magna adipiscing eget. Donec sed ante at massa tincidunt porttitor
 vitae vel lectus. Sed facilisis feugiat felis, ultricies aliquam ante iaculis
 et. Suspendisse fringilla, purus nec convallis cursus, nunc lectus pharetra
 ipsum, nec hendrerit sem nunc eu nulla. Nam neque magna, faucibus vitae ante
 nec, hendrerit bibendum nunc.

\end{document}
  • Why my code isn't prettified (no code highlighting)? – macxpat Jul 10 '13 at 10:21
  • 1
    You shouldn't use the <pre> and </pre> tags; just indent the code with four spaces: select the part and hit Control-K or click the {} button. – egreg Jul 10 '13 at 10:51
6

The following relies solely on enumitem by creating an special newline alignment through \SetLabelAlign. It allows an abstract way for obtaining the alignment you're after, can be incorporated in a specific style (if needed) and doesn't affect all the enumerate environments like in Gonzalo's answer:

enter image description here

\documentclass{article}
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\SetLabelAlign{newline}{\makebox[\dimexpr\linewidth-\labelsep][l]{#1}}%
\begin{document}

Nunc convallis tincidunt scelerisque. Praesent ac mattis ligula, dictum 
condimentum enim. Donec convallis id lorem vel lobortis. Duis dapibus metus 
ut risus egestas, in lobortis elit ultricies. Nam eu odio aliquam, 
ullamcorper quam sed, placerat massa.

\begin{enumerate}[
  align=newline,
  label=\textbf{Question \arabic*},
  leftmargin=0pt,
  itemindent=\dimexpr\labelwidth+\labelsep]
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan 
    pulvinar magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed 
    dictum. Nulla suscipit leo et luctus facilisis. Vivamus a lorem at libero 
    elementum blandit eu quis diam. Fusce mollis lorem a diam consequat, non 
    fermentum massa auctor.
  \item Vivamus fringilla eget nisl at mattis. Sed commodo iaculis est, 
    adipiscing pretium magna adipiscing eget. Donec sed ante at massa tincidunt 
    porttitor vitae vel lectus. Sed facilisis feugiat felis, ultricies aliquam 
    ante iaculis et. Suspendisse fringilla, purus nec convallis cursus, nunc 
    lectus pharetra ipsum, nec hendrerit sem nunc eu nulla. Nam neque magna, 
    faucibus vitae ante nec, hendrerit bibendum nunc.
\end{enumerate}

\end{document}
  • Werner's solution is the solution I was looking for! It is robust, simple and elegant. If we use this list style several times in a document, we can define a new list style with for example \newlist{enumquest}{enumerate}{1} and \setlist[enumquest]{align=newline,label=\textbf{Question \arabic*},leftmargin=0pt,itemindent=\dimexpr\labelwidth+\labelsep} after the \SetLabelAlign definition. Then we can use the new list with \begin{enumquest} \item blah1 \item blah2 \end{enumquest}. – macxpat Jul 6 '13 at 12:38
2

Adjust the value for labelsep making it -\labelwidth:

\documentclass{article}  
\usepackage{enumitem}   
\usepackage{etoolbox}

\makeatletter
\expandafter\apptocmd\expandafter{\csname\string\enumerate\endcsname}{\apptocmd{\@item}{\mbox{}\\*}{}{}}{}{}
\makeatother

\begin{document}

Nunc convallis tincidunt scelerisque. Praesent ac mattis ligula, dictum condimentum enim. Donec convallis id lorem vel lobortis. Duis dapibus metus ut risus egestas, in lobortis elit ultricies. Nam eu odio aliquam, ullamcorper quam sed, placerat massa.

\begin{enumerate}[align=left,label=\textbf{Question \arabic*},leftmargin=!,labelsep=-\labelwidth]
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan pulvinar magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed dictum. Nulla suscipit leo et luctus facilisis. Vivamus a lorem at libero elementum blandit eu quis diam. Fusce mollis lorem a diam consequat, non fermentum massa auctor.
\item Vivamus fringilla eget nisl at mattis. Sed commodo iaculis est, adipiscing pretium magna adipiscing eget. Donec sed ante at massa tincidunt porttitor vitae vel lectus. Sed facilisis feugiat felis, ultricies aliquam ante iaculis et. Suspendisse fringilla, purus nec convallis cursus, nunc lectus pharetra ipsum, nec hendrerit sem nunc eu nulla. Nam neque magna, faucibus vitae ante nec, hendrerit bibendum nunc.
\end{enumerate}

\end{document}

enter image description here

In the example above I also made some modifications to the original code, using the etoolbox package to change the behaviour of \item inside an enumerate environment so that after the label the text will start in a new line (I borrowed some code from Philippe Goutet's answer to Starting an enumerate of an enumerate on next line?). Of course, this is optional and you can use your original settings with the suggested value for the labelsep key.

  • Thanks for the fast answer. But could'nt we replace the labelsep=-19.5pt by something more universal, that would fit any document layout / margins ? – macxpat Jul 5 '13 at 23:33
  • @macxpat sure! Please see my updated answer. – Gonzalo Medina Jul 5 '13 at 23:35
  • OK, I see it's related to the label width, not the margin (didn't notice the minus sign). I will use the original version because I want to keep the normal behaviour for item in other parts of the document. How did you came up in the first place with 19.5pt: luck or a measurement tool ? And I'm new to stackexchange, how do you get color coded code ? Thanks a lot. – macxpat Jul 5 '13 at 23:59

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.