My question is if it is possible to draw vertical lines in the algorithm package. I have seen the following question:

Vertical line for pseudo code

But I don't want to use algorithm2e because it changes the format of the algorithm. Is it possible to handle that with the algorithm package?


1 Answer 1


Welcome to TeX-SE! With tikz and tikzmark you can certainly add lines. Whether or not this is the most efficient way to produce such an output, i.e. whether or not there is a package that does all that out of the box, I do not know.

\documentclass[two column,conference]{IEEEtran}
    1: Initialization of parameters \\
    2: Randomly generate population using Eq. 28\\
    \tikzmarknode{3}{3}: \textbf{for} u=1:k \\
    \tikzmarknode{4}{4}: \textbf{for} s=1:i$_{c}$\\
    5:  Randomly generated X$_{s}^{u}$ in da\\
    \tikzmarknode{6}{6}: \textbf{end for} \\
    \tikzmarknode{7}{7}: \textbf{end for}\\
    8: End of initialization step\\
    9: \textbf{While} Maximum number of iteration reached \textbf{do}\\
    10:  Construction and assessment of new candidate\\
    11: \textbf{if} ($rand (0,1)\leq$ cpu)\\
    12: Choose random no \\
    13: \textbf {if} ($rand (0,1 ) \leq$ cpu) \\
    14:  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    15: \textbf{end if} \\
    16: \textbf{else} \\
    17: Evaluate fitness function a: F(a) using Eq. 17\\
    27: End of the construction and assessment step\\
    28: Construction and assessment of new candidate: a   \\
    29: if (F(y) has best value than the worst member \\
    30: Replace DA member with new candidate: a\\
    31: else\\
    32: Discard x\\
    33: \textbf{endif}\\
    34: End of update\\
    35: Until a preset termination criterion is met\\
    36: end \textbf{while}\\
\begin{tikzpicture}[overlay,remember picture]
 \draw[blue,thick] (3.west) -- ++ (-4pt,0pt) |- (7);
 \draw[red,thick] (4.west) -- ++ (-2pt,0pt) |- (6);

enter image description here

You must log in to answer this question.

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