5

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}
N.N.
  • 36,163
projetmbc
  • 13,315

3 Answers3

13

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

N.N.
  • 36,163
  • @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
7

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
% https://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}
Peter Grill
  • 223,288
  • 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
  • Have defined custom environments for you to keep the code as close as possible to what you have given in the MWE. Not that it is \begin{Action}...\end{Action} not \begin[Action]{step}..\end{step} – Peter Grill Oct 26 '11 at 17:08
  • @Werner: Good suggestion, but I think it is simpler to just provide two environment as I have in the updated solution. – Peter Grill Oct 26 '11 at 17:10
  • Thanks for all ! I'll try to have the feature I need (don't help me, it's time to me to use the indicatins of Werner, hoping that I'll not "break" my head...). – projetmbc Oct 26 '11 at 17:18
6
\usepackage{enumerate}

\begin{enumerate}[{Action}~1:]
\item Blah
\item Blah blah
\end{enumerate}
\begin{enumerate}[{Step}~1:]
\item Blah
\item Blah blah
\end{enumerate}
Boris
  • 38,129