5

It doesn't seem to be formatted using instructions from the usual algorithm libraries of Latex.enter image description here

It seems to be simply formatted text, I am uncertain.

Rte
  • 67

1 Answers1

10

A simple way to do this is to use the enumitem package to make nested lists. The trick of starting the list on a new line is adapted from this answer. This is not needed if every item contains some text, but is necessary if a step is embedded directly as an item of the list. If a step will never be embedded like this, then the before={\apptocmd{\item}{\mbox{}}{}{}} code is not required.

\documentclass{article}
\usepackage{enumitem}
\usepackage{etoolbox}
\newlist{algolist}{enumerate}{3}
\setlist*[algolist]{leftmargin=*,before={\apptocmd{\item}{\mbox{}}{}{}}}
\setlist*[algolist,1]{label={\itshape Step \arabic*:}}
\setlist*[algolist,2]{label={\itshape Step \arabic{algolisti}.\arabic*:}}
\setlist*[algolist,3]{label={\itshape Step \arabic{algolisti}.\arabic{algolistii}.\arabic*:}}
\begin{document}
\begin{algolist}
\item This is the first step of the algorithm. It can have many lines in it and they will wrap as you would expect. 
\item This is the second step of the algorithm.
    \begin{algolist}
    \item This is the first substep of the second step of the algorithm.
    \item This is the second substep of the second step of the algorithm.
        \begin{algolist}
        \item This is the first substep of the second substep of the algorithm.
        \item This is the second substep of the second substep of the algorithm.
        \end{algolist}
    \end{algolist}
\end{algolist}
\end{document}

output of code

Alan Munn
  • 218,180
  • What's the \mbox{} for? – egreg Feb 05 '24 at 21:28
  • 1
    @egreg It's the trick used in answer I linked to to make a new level start on the next line. If there's a better way to do that, I'd be happy to use it. – Alan Munn Feb 05 '24 at 21:31
  • It's not needed if every step has text before the substeps. – egreg Feb 05 '24 at 21:40
  • @egreg True, but I guess it's doing no harm, and will allow for the no text case, which is why I put it there. – Alan Munn Feb 05 '24 at 21:44
  • @egreg I've added a bit more explanation. – Alan Munn Feb 05 '24 at 21:50
  • I don't think it's needed for this case, even if a step starts with substeps, but that's up to the OP. I'd also add noitemsep at level 1 and nosep at levels 2 and 3, in order to match the picture. – egreg Feb 05 '24 at 21:56
  • @AlanMunn @egreg Yes is not needed if every step has text, although an empty item can be written as \item \mbox{} by the user. It also affects somehow spacing, if you comment it out, you see the difference in 2.2.1 and 2.2.2 become one liners. – yannisl Feb 06 '24 at 03:13