algpseudocode 中的垂直线

algpseudocode 中的垂直线

我试图让垂直线出现在这里:

\begin{spacing}{0.8}
\begin{algorithm}
\caption{Cost-Vector Algorithm}\label{costalgorithm}
\begin{algorithmic}[1]
\Require \begin{varwidth}[t]{\linewidth}
                  Training sentences $S_{i}$\par      
               \end{varwidth}
\Ensure Sentence instances with cost-vectors for training $S_{i,c_i}$
\Function{generateCosts}{$EV_{i,v,r}$}
\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$}
\Else 
\State continue
\EndIf
\EndFor
\If {$min(c) > APE_t$}
\State $c_{i,no\_property}:=0$
\Else 
\State $c_{i,no\_property}:=\infty$
\EndIf
\State push($S_{i,c_{i}},(s,c_{i}))$
\EndFor\label{endfor}
\State \textbf{return} $S_{i,c_{i}}$
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{spacing}

这是在我的文档开始之前加载的:

\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}%http://ctan.org/pkg/algorithmicx
% \usepackage[linesnumbered,ruled]{algorithm2e}
\algrenewcommand\textproc{}% Used to be \textsc
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\usepackage{calc} % for \widthof
\algrenewcommand\algorithmicensure{%
  \makebox[\widthof{\textbf{Require:}}][l]{\textbf{Ensure:}}} 

目前它看起来像:

在此处输入图片描述

我正在尝试模拟这个链接:https://cl.ly/0d3g3k1c3D1g

答案1

您可以使用\usepackage[ruled, vlined, linesnumbered]{algorithm2e}

下次请给出 MWE。

我希望这就是你想要的:

\documentclass[a4paper, 12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[ruled, vlined, linesnumbered]{algorithm2e}

\begin{document}

\begin{algorithm}
\DontPrintSemicolon
\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$
      }
      \Else
      {
        continue
      }
    }
    \uIf{$\min \left( c \right)  > APE_t$}
    {
      $c_{i,no\_property} \coloneqq 0$
    }
    \Else
    {
      $c_{i,no\_property} \coloneqq \infty$
    }
    $\text{push} \left( S_{i,c_{i}}, \left( s,c_{i} \right) \right)$
  }\label{endfor}
  \Return{$S_{i,c_{i}}$}
}
\caption{Cost-Vector Algorithm}\label{costalgorithm}
\end{algorithm}
\end{document}

我改变了一些小事情,例如:

  • coloneqq代替:=
  • 添加了第 7 行中缺失的括号
  • \min代替min
  • ...

输出: 在此处输入图片描述

相关内容