4

I am using algorithm2e for formatting pseudo-code: is it possible to compress single-instructions control structure to one single line?

For example I would like to modify this so that l.sort() appears on the same line as foreach:

\begin{algorithm}[htb]
  \ForEach{$l \in list\_of\_lists$}{  $l.sort()$\;  }
  \caption{...}
  \label{...}
\end{algorithm}

Thanks in advance

0

1 Answer 1

3

You could use the command \lForEach. See https://www.tug.org/texlive/Contents/live/texmf-dist/doc/latex/algorithm2e/algorithm2e.pdf page 33.

\begin{algorithm}[htb]
  \lForEach{$l \in list\_of\_lists$}{  $l.sort()$\;  }
  \caption{...}
  \label{...}
\end{algorithm}
3
  • 1
    Works like a charm, thanks a lot! I didn't see that, it is in the examples but even google coldn't find it by searching "one line for" or "single line control structure"
    – Davide
    Jul 7, 2013 at 11:00
  • 1
    I also removed the \; in order to prevent a blank line to be added.
    – Davide
    Jul 7, 2013 at 11:01
  • 1
    You're welcome! I know how it is, sometimes google is not very helpfull with latex issues, even easy ones in retrospective. Started to use this site some days ago and it's so helpfull and I learned a lot.
    – Ascurion
    Jul 7, 2013 at 11:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .