3

Just starting to play around with the algorithm2e package and I have difficulties to figure out the things I need.

Here is my minimal working example:

\documentclass[10pt,a4paper]{article}
\usepackage[lined,boxed,commentsnumbered,german]{algorithm2e}
\begin{document}
\begin{algorithm}
\ForAll{$i\in \left[n\right]$ in parallel}{
    $a\leftarrow b$\;
}    
\textbf{repeat} $\left\lceil\log n \right\rceil$ \textbf{times}\;\Indp{
\If{$b > 1$}{
    $b\leftarrow c$
}}
\end{algorithm}
\end{document}

which gives me this: Example

  1. Instead of 'forall the' I would prefer to have just 'for all'. Instead of 'in parallel do' I would prefer to have it together as 'in parallel do'. How do I achieve that?
  2. How do I define my own macro 'repeat', so that is has an 'end'-statement, 'times' is inserted and a working vertical line at the left border?
  3. Is it possible to remove the 'end' of the 'if'-statement? 'lIf' is neat, but not really what I am looking for..

I tried to understand the documentation and the threads here on stackexchange, but the examples are quite complicated for a beginner, so I would be grateful for any advice.

Thanks in advance!

[not a native english speaker]

1
  • \SetKwFor{ForAll}{for all}{do}{end forall} for the first question
    – user31729
    Commented Apr 20, 2016 at 9:42

1 Answer 1

2

A first version, not complete so far!

The \SetKwX macros define much of the keywords and appearance style, but not all is possible, apparently, without manual interaction on the precise position when the \ForAll etc. statements are used.

\documentclass[10pt,a4paper]{article}
\usepackage[lined,boxed,commentsnumbered,german]{algorithm2e}

\SetKwFor{ForAll}{for all}{do}{end}
\SetKwRepeat{Repeat}{repeat}{end}
%\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{}
\begin{document}
\begin{algorithm}
\ForAll{$i\in \left[n\right]$ in parallel}{
    $a\leftarrow b$\;
}    
\Repeat($\left\lceil\log n \right\rceil$ times){}{%
  \lIf{$b > 1$}{\\
    $b\leftarrow c$
  }
}
\end{algorithm}
\end{document}

enter image description here

2
  • Thanks for that, these answered most of my questions. Together with '\Indp{' it should definitely work.
    – CurryCurry
    Commented Apr 20, 2016 at 20:05
  • @CurryCurry: Apparently I missed \lndp -- well, if it fits you needs, you can consider to accept it later on
    – user31729
    Commented Apr 20, 2016 at 20:07

You must log in to answer this question.

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