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 would like to obtain the following output :

Bla, bla, here are the actions to do.

    Action 1
        Bla, bla, bla...

    Action 2
        Bla, bla, bla...

    Action 3
        Bla, bla, bla...

When the preceding actions have been done, you must do the following things.

    Thing 1
        Bla, bla, bla...

    Thing 2
        Bla, bla, bla...

    Thing 3
        Bla, bla, bla...

The LaTeX code could look like :

Bla, bla, here are the actions to do.

\begin[Action]{step}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{step}

When the preceding actions have been done, you must do the following things.

\begin[Thing]{step}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{step}
share|improve this question
add comment

3 Answers

up vote 12 down vote accepted

You can use \newenvironment to make a step by step environment, steps:

\documentclass{article}

\usepackage{enumitem}

\newenvironment{steps}[1]{\begin{enumerate}[label=#1 \arabic*]}{\end{enumerate}}

\makeatletter% http://tex.stackexchange.com/questions/29517/forcing-new-line-after-item-number-in-enumerate-environment/29518#29518
\def\step{%
   \@ifnextchar[ \@step{\@noitemargtrue\@step[\@itemlabel]}}
\def\@step[#1]{\item[#1]\mbox{}\\\hspace*{\dimexpr-\labelwidth-\labelsep}}
\makeatother

\begin{document}

\begin{steps}{Action}
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\begin{steps}{Thing}
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\end{document}

Output

To further refine this approach you can declare the environment using the LaTeX3 function \DeclareDocumentEnvironment. It lets you specify optional arguments and set defaults for them. The following declares a new environment, steps, which if it's not given any argument defaults to the label "Steps":

\documentclass{article}

\usepackage{enumitem}
\usepackage{xparse}

\DeclareDocumentEnvironment{steps}%
{O{Step}}% If no argument is given the label defaults to 'Step'
{\begin{enumerate}[label=#1 \arabic*]}%
{\end{enumerate}}

\makeatletter% http://tex.stackexchange.com/questions/29517/forcing-new-line-after-item-number-in-enumerate-environment/29518#29518
\def\step{%
   \@ifnextchar[ \@step{\@noitemargtrue\@step[\@itemlabel]}}
\def\@step[#1]{\item[#1]\mbox{}\\\hspace*{\dimexpr-\labelwidth-\labelsep}}
\makeatother

\begin{document}

\begin{steps}
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\begin{steps}[Action]
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\begin{steps}[Thing]
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\end{document}

Output

share|improve this answer
    
@projetmbc I've updated my answer to include a solution with optional arguments that can have defaults, e.g. see how it produces "Steps 1, Step 2, Step 3" when the environment steps is given no argument. –  N.N. Oct 26 '11 at 17:51
    
Thanks for this, I was playng with this... You've been faster than me... –  projetmbc Oct 26 '11 at 18:41
    
@projetmbc If you come up anything significant your should post it as an answer (i.e. I'm curious!). –  N.N. Oct 26 '11 at 19:09
    
This is similar to the previous answer so no reason to post it... –  projetmbc Oct 26 '11 at 20:27
add comment

Use the enumitem package create the label for each Action line item:

\begin{enumerate}[label=Action \arabic*,align=left, leftmargin=2.0cm]

Since you wanted a new line after the beginning of the list I have used the solution from Forcing new line after item number in enumerate environment to define \step:

\makeatletter
\def\step{%
   \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
\def\@myitem[#1]{\item[#1]\mbox{}\\}
\makeatother

Using these yields the desired results:

enter image description here

You can also use a custom environment for each section:

\documentclass{article}
\usepackage{enumitem}

% Since you want a blank line after the begin of a list
% http://tex.stackexchange.com/questions/29517/forcing-new-line-after-item-number-in-enumerate-environment
\makeatletter
\def\step{%
   \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
\def\@myitem[#1]{\item[#1]\mbox{}\\}
\makeatother


% Custom environments
\newenvironment{Action}{%
    \begin{enumerate}[label=Action \arabic*,align=left, leftmargin=2.0cm]%
}{
    \end{enumerate}%
}

\newenvironment{Thing}{%
    \begin{enumerate}[label=Thing \arabic*,align=left, leftmargin=2.0cm]%
}{
    \end{enumerate}%
}




\begin{document}
\noindent
Bla, bla, here are the actions to do.


\begin{Action}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{Action}

\noindent
When the preceding actions have been done, you must do the following things.

\begin{Thing}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{Thing}
\end{document}
share|improve this answer
    
Is it possible to use back returns in one item ? –  projetmbc Oct 26 '11 at 16:39
    
Not sure what you mean? Are you referring to the indentation? Have updated the code so see if that is exactly what you wanted. –  Peter Grill Oct 26 '11 at 16:45
    
Thanks, that's great ! One last thing : is there a way to define a new environment like in my proposition ? It's only for semantic reasons. –  projetmbc Oct 26 '11 at 16:54
    
@projetmbc: You could define a new environment, but the optional argument [Action] or [Thing] will have to be after the steps environment, as in \begin{steps}[Action]... –  Werner Oct 26 '11 at 16:56
    
@PeterGrill: Using the xparse package, you could define steps using \NewDocumentEnvironment{steps}{O{Action} O{,}}{..}{..} which would default to \begin{steps}[Action], but also allow for passing additional options to enumerate via a second optional argument: \begin{steps}[Thing][topsep=5pt]. Just a suggestion. –  Werner Oct 26 '11 at 16:59
show 3 more comments
\usepackage{enumerate}

\begin{enumerate}[{Action}~1:]
\item Blah
\item Blah blah
\end{enumerate}
\begin{enumerate}[{Step}~1:]
\item Blah
\item Blah blah
\end{enumerate}
share|improve this answer
add comment

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.