我正在尝试为我的算法编写一些伪代码。是否可以在按钮和算法顶部添加线条?如果可以,该怎么做?
代码:
\documentclass{article}
\usepackage[]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{$next\_id, speed,stop\_distance, mac$}
\KwResult{Find the initializer. }
int $next\_id1$ = find a record with $speed > 30$ for this $mac$;\\
int $next\_id2$ = find record with $speed <7$ and $stop\_distance < 60$ for this mac;\\
\If{$next\_id1 < next\_id2$}{
find the related $stop\_name$ for this mac;
return $stop\_name$;
}
\caption{Algorithm to find intializer.}
\end{algorithm}
\end{document}
答案1
您可以将ruled
选项用于包中algorithm2e
。
\documentclass{article}
\usepackage[ruled]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{$next\_id, speed,stop\_distance, mac$}
\KwResult{Find the initializer. }
int $next\_id1$ = find a record with $speed > 30$ for this $mac$;\\
int $next\_id2$ = find record with $speed <7$ and $stop\_distance < 60$ for this mac;\\
\If{$next\_id1 < next\_id2$}{
find the related $stop\_name$ for this mac;
return $stop\_name$;
}
\caption{Algorithm to find intializer.}
\end{algorithm}
\end{document}
还有其他选项,如手册中的屏幕截图所示: