This is my attempt in LaTeX (for convenience, it has been translated into English):
Code: Select all
\documentclass{article}
\usepackage[vlined]{algorithm2e}
\makeatletter
\renewcommand{\algocf@Hlne}{%
\rule{.5em}{.4pt}%
\smash{\rule[\dimexpr-.5ex+.2pt]{1ex}{1ex}}%
}
\makeatother
\SetKw{Read}{read}
\SetKw{Write}{write}
\SetKw{And}{and}
\begin{document}
\begin{algorithm}
\DontPrintSemicolon
\Read{$n,\,x,\,y$} (non-zero natural numbers, $x \leq n$, $y \leq n$)\;
$nr \gets 0$\;
\While{$i \gets n,\,1,\,-1$}{
\eIf{$i~\%~x = 0$ \And $i~\%~y \neq 0$}{
$nr \gets nr + 1$\;
}{
\If{$i~\%~x \neq 0$ \And $i~\%~y = 0$}{
$nr \gets nr + 1$\;
}
}
}
\Write{nr}\;
\end{algorithm}
However, I don't know how to make the lines like in the given pseudocode. I don't see how I could do it with \algocf@Hlne, because that deals with the horizontal line as I understand it, and looking at how \algocf@Vline is in algorithm2e doesn't provide me any clue. How would I accomplish my goal? To be precise, the line should start from the left of the keyword and go all the way down until where the little box is. Additionally, the line shouldn't cross through any other keywords, such as with if and else there. Also, all keywords on the first level should be aligned, so that the line goes outside of the block instead of offsetting what's inside; in other words, it should be like this:
Code: Select all
read n,x,y
nr←0
┌for i←n,1,-1 do
│ write i
│ read x
└■
write nr
Code: Select all
read n,x,y
nr←0
┌for i←n,1,-1 do
│ write i
│ read x
└■
write nr