为什么最后一行的行号对不齐

发布于 2025-03-14 13:12:57
\begin{algorithm}

\small
\KwIn{数据图$G=(V_G, E_G)$, 整数参数$K$, 以及查询顶点$v_q$ }
\KwOut{对应的包含$v_q$的$K$-truss社区集合}
visited= $\varnothing$, $l = 0$ \label{code:truss-search:init} 

\For{$v_q$的每一个邻居$u$}
{
 \If{边$(v_q,u)$的{\rm truss}不小于$k$且并未访问过}
 {
  visited = visited$\cup \{(v_q, u)\}$\;
  $l ++$\;
  $C_l=\varnothing, Q=\varnothing$ \;
  $Q$.push$(v_q, u)$\;
  \While{$Q \neq \varnothing$}
  {
   $(x,y) = Q.$pop()\;
   $C_l.$push$((x,y))$\;
   \For{$z\in N(x)\cap N(y)$}
   {
    \If{$(x,z)$和$(y,z)$的{\rm truss}值均不小于$K$}
    {
     \If{$(x,z)$未访问过}
     {
      $Q.$push$((x,z))$\;
      visited = visited $\cup \{(x,z)\}$
     }
     \If{$(y,z)$未访问过}
     {
      $Q$.push$((y,z))$\;
      visited = visited $\cup \{(y,z)\}$
     }
    }
   }
  }
 }
}
Return \{$C_1$, $\cdots$, $C_l$\}
 
\caption{$K$-truss社区搜索在线查询算法}
 \label{alg:truss:search:online}
\end{algorithm}

QQ20250314-130608.png

查看更多

关注者
0
被浏览
157
1 个回答
雾月
雾月 4小时前
这家伙很懒,什么也没写!

实际上是中间的行号比前两行和最后一行更靠近右侧一点。这应该是 algorithm2e 的 bug。

在导言区重定义 \algocf@Vline \algocf@Vsline 即可。

\documentclass{ctexart}
\usepackage{amsmath,amssymb}
\usepackage[linesnumbered,lined,ruled,noend]{algorithm2e}
\SetArgSty{textrm}
\SetAlgorithmName{算法}{算法}{算法目录}

\makeatletter
\@ifpackagelater{algorithm2e}{2017/07/19}{}{% current version 2017/07/18
%%%%%%%%% block with a vertical line end by a little horizontal line
\renewcommand{\algocf@Vline}[1]{%     no vskip in between boxes but a strut to separate them, 
  \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
  \algocf@push{\skiprule}%        move to the right before the vertical rule
  \hbox{\kern-.4pt\vrule%   %% <- add \kern
    \vtop{\algocf@push{\skiptext}%move the right after the rule
      \vtop{\algocf@addskiptotal #1}\Hlne}}\vskip\skiphlne% inside the block
  \algocf@pop{\skiprule}%\algocf@subskiptotal% restore indentation
  \nointerlineskip}% no vskip after
%
%%%%%%%%% block with a vertical line
\renewcommand{\algocf@Vsline}[1]{%    no vskip in between boxes but a strut to separate them, 
  \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
  \algocf@bblockcode%
  \algocf@push{\skiprule}%        move to the right before the vertical rule
  \hbox{\kern-.4pt\vrule%               the vertical rule %% <- add \kern
    \vtop{\algocf@push{\skiptext}%move the right after the rule
      \vtop{\algocf@addskiptotal #1}}}% inside the block
  \algocf@pop{\skiprule}% restore indentation
  \algocf@eblockcode%
}
}
\makeatother

\begin{document}

\begin{algorithm}
\small
\KwIn{数据图$G=(V_G, E_G)$, 整数参数$K$, 以及查询顶点$v_q$ }
\KwOut{对应的包含$v_q$的$K$-truss社区集合}
visited= $\varnothing$, $l = 0$ \label{code:truss-search:init} 

\For{$v_q$的每一个邻居$u$}
{
 \If{边$(v_q,u)$的{\rm truss}不小于$k$且并未访问过}
 {
  visited = visited$\cup \{(v_q, u)\}$\;
  $l {++}$\;
  $C_l=\varnothing, Q=\varnothing$ \;
  $Q$.push$(v_q, u)$\;
  \While{$Q \neq \varnothing$}
  {
   $(x,y) = Q.$pop()\;
   $C_l.$push$((x,y))$\;
   \For{$z\in N(x)\cap N(y)$}
   {
    \If{$(x,z)$和$(y,z)$的{\rm truss}值均不小于$K$}
    {
     \If{$(x,z)$未访问过}
     {
      $Q.$push$((x,z))$\;
      visited = visited $\cup \{(x,z)\}$
     }
     \If{$(y,z)$未访问过}
     {
      $Q$.push$((y,z))$\;
      visited = visited $\cup \{(y,z)\}$
     }
    }
   }
  }
 }
}
Return \{$C_1$, $\cdots$, $C_l$\}
 
\caption{$K$-truss社区搜索在线查询算法}
 \label{alg:truss:search:online}
\end{algorithm}

\end{document}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览