[Tex/LaTex] Vertical lines in algpseudocode


I am trying to get vertical lines to appear in this:

\caption{Cost-Vector Algorithm}\label{costalgorithm}
\Require \begin{varwidth}[t]{\linewidth}
                  Training sentences $S_{i}$\par      
\Ensure Sentence instances with cost-vectors for training $S_{i,c_i}$
\State $S_{i,c_{i}} = \left[\right]$
\ForAll{$s \in S , v \in EV $}
\State $c_{i} = \left\{\right\}$
\State set $region \;r= EV_{i,r}$
\For {$p \leftarrow 1, properties$}
\State $c_{i,p}:=cost(kb_{r,p},v_{i,r}$
\If {$c_{p} > Cost_t$}
\State {$c_{p}:=\infty$}
\State continue
\If {$min(c) > APE_t$}
\State $c_{i,no\_property}:=0$
\State $c_{i,no\_property}:=\infty$
\State push($S_{i,c_{i}},(s,c_{i}))$
\State \textbf{return} $S_{i,c_{i}}$

And this is loaded before my document starts:

\usepackage{algorithm}% http://ctan.org/pkg/algorithms
% \usepackage[linesnumbered,ruled]{algorithm2e}
\algrenewcommand\textproc{}% Used to be \textsc
\usepackage{calc} % for \widthof

Currently it looks like:

enter image description here

I am trying to emulate this link: https://cl.ly/0d3g3k1c3D1g.

Best Answer

You can use \usepackage[ruled, vlined, linesnumbered]{algorithm2e}.

Please give a MWE next time.

I hope, this is what you want:

\documentclass[a4paper, 12pt]{article}
\usepackage[ruled, vlined, linesnumbered]{algorithm2e}


\KwIn{Training sentences $S_{i}$}
\KwOut{Sentence instances with cost-vectors for training $S_{i,c_i}$}
\SetKwBlock{Begin}{function}{end function}
\Begin($\text{generateCosts} {(} EV_{i,v,r} {)}$)
  $S_{i,c_{i}} = \left[ \right]$\;
  \ForAll{$s \in S, v \in EV $}
    $c_{i} = \left\lbrace \right\rbrace$\;
    set $region \; r = EV_{i,r}$\;
    \For{$p \leftarrow 1, properties$}
      $c_{i,p} \coloneqq cost \left( kb_{r,p},v_{i,r} \right)$\;
      \uIf{$c_{p} > Cost_t$}
        $c_{p} \coloneqq \infty$
    \uIf{$\min \left( c \right)  > APE_t$}
      $c_{i,no\_property} \coloneqq 0$
      $c_{i,no\_property} \coloneqq \infty$
    $\text{push} \left( S_{i,c_{i}}, \left( s,c_{i} \right) \right)$
\caption{Cost-Vector Algorithm}\label{costalgorithm}

I changed some little things, like:

  • coloneqq instead of :=
  • missing bracket in line 7 added
  • \min instead of min
  • ...

Output: enter image description here