[Tex/LaTex] A step by step environment

enumitemformattinglists

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}

Best Answer

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

Related Question