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.

I have an enumeration environment in my LaTeX document consisting of several numbered steps. Now I need to indent some of these steps. I am using the following command to achieve this indentation for one item:

{\setlength\itemindent{2cm} 
   \item Some item text...
}

It works for short item texts, but in the case of longer texts that lead to line breaks, the subsequent lines are not indented. See the following LaTeX code for an example:

\begin{enumerate}
\item This is a normal item without any indentation.
{\setlength\itemindent{2cm} 
\item This is an indented item with a long text that causes a line break. Unfortunately, the new line is not indented. 
}
\item This is a normal item without any indentation.
\end{enumerate} 

(Unfortunately I am not allowed to post an image of the output as I'm a new user...)

The first line of the second item is indented by 2cm, but all subsequent lines are not. Can anyone give me a hint on how to get the subsequent lines indented, too?

share|improve this question

migrated from stackoverflow.com Jul 2 '12 at 15:25

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 6 down vote accepted

As ErikYou suggests, one normally would nest an enumerated list within an enumerated list to get this effect. However, in your case, this would in effect start a new list with its own counter. So, I would suggest you use the IndentedEnumerate environment defined below which starts the nested list so that its enumeration continues on from the previous list and yields:

enter image description here

Notes:

  • This is only set up for one level of nesting -- It will need further enhancements if more than one level of nesting if desired.
  • If the first item is to be indented, you need to add \item[] before starting the IndentedEnumerate environment.
  • If you wish this to work without the enumitem package package, the only tweaks necessary should be to modify how the label is specified for the indented list.
  • The showframe package was used just to show the page margins.

Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{enumitem}

\newcounter{ListStartCount}%
\newenvironment{IndentedEnumerate}[1][]{%
    \setcounter{ListStartCount}{\theenumi}%
    \stepcounter{ListStartCount}%
    \begin{enumerate}[start=\theListStartCount,label={\arabic*.},#1]%
}{%
    \setcounter{enumi}{\theListStartCount}%
    \end{enumerate}%
}%

\begin{document}
\begin{enumerate}
\item[]
\begin{IndentedEnumerate}
\item This is the frist item with indentation, so need \verb|\item[]| before this.
\end{IndentedEnumerate} 
\item This is a normal item without any indentation.
%
\begin{IndentedEnumerate}
\item This is an indented item with a long text that causes a line break. Now, the enumeration is continued and the new line is indented. 
\end{IndentedEnumerate} 
%
\item This is a normal item without any indentation.
\end{enumerate} 
\end{document}
share|improve this answer
    
Works like a charm, thanks! However, there's one special case that doesn't work yet. Sometimes, the indented enumeration has to be the first "item" in the outer enumeration. In that case, the compiler returns an error message stating something's wrong--perhaps a missing item - I guess the outer \theenumi hasn't been initialized. How do I get this case to work? I guess I could just add \setcounter{enumi}{1} to the beginning of each outer enum, but there's probably a nicer way handling this in the environment definition... –  MichaelB Jul 3 '12 at 21:12
    
@MichaelB: For the first item you need to add \item[]. Have updated the solution to show that. –  Peter Grill Jul 3 '12 at 21:27
    
That did the trick, now everything works as expected, thank you so much! :) –  MichaelB Jul 3 '12 at 21:43

enumitem provided the resume. This allows one to terminate a list and restart it with the same counter, perhaps with a different layout configuration. Here's a brief example, duplicating Peter's answer:

enter image description here

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{enumitem}% http://ctan.org/pkg/enumitem
\newcommand{\modifyenum}[1]{%
  \end{enumerate}
  \begin{enumerate}[resume,#1]
}
\begin{document}
\begin{enumerate}[leftmargin=2cm]
  \item This is the first item with indentation.
  \modifyenum{leftmargin=1cm}
  \item This is a normal item with a \verb|1cm| indentation.
  \modifyenum{leftmargin=2cm}
  \item This is an indented item with a long text that causes a line break. Now, the enumeration is continued and the new line is indented. 
  \modifyenum{leftmargin=1cm}
  \item This is a normal item with a \verb|1cm| indentation.
  \modifyenum{resume,leftmargin=*}
  \item Here is a normal flush-left item.
  \item Here is a normal flush-left item.
  \item Here is a normal flush-left item.
\end{enumerate}
\end{document}

The above MWE uses \modifyenum{<new list configuration>} to terminate the existing enumerate list and restart it with any new list preferences using resume.

showframe merely highlights the text block boundary and is not needed otherwise.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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