我需要修复这个 LaTeX 代码的对齐方式。
if当我编译它时,输出的, for,语句对齐错误else。
\begin{algorithm}[H]
\caption{:The $ASP\_Tree$ algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{TV database and min\_sup }
\Output{Bla bla bla}
\KwData{bla bla bla}
\Procedure{Tree}{$TV_i, min\_sup$}
{
\State {$[Root] \leftarrow [NULL]$} \newline
\For {$i=1$ to $N$} {\label{forins} \newline
{
%\Statex \Comment {\%Comments: insert TV values into the tree based on rules}
\State {$Root \leftarrow TV_1$}
\State {$i \leftarrow i+1$} \newline
\If {TV_i \textgreater Root}
\State Root \gets TV_i
\ELSIF {TV_i\leq Root}
\State i\gets i+1
\ELSE
\State do something interesting
\ENDIF
}
\EndFor
}
\EndProcedure
\end{algorithm}
Run Code Online (Sandbox Code Playgroud)
您的问题在于您混合了不同包的符号,这些符号本质上是不兼容的。您应该选择或 (提供和),而不是两者都选择。algorithm2e algorithmicxalgpseudocodealgcompatible
这是algorithm2e您可能想要的实现:
\documentclass{article}
\usepackage{algorithm2e,amsmath}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output\,}
\SetKwInOut{Data}{Data}
\SetKwProg{Tree}{Tree}{}{EndTree}
\begin{document}
\begin{algorithm}[H]
\caption{The ASP\_Tree algorithm}
\Input{TV database and min\_sup}
\Output{Bla bla bla}
\Data{bla bla bla}
\Tree{$TV_i, min\_sup$}{
$[\text{Root}] \gets [\text{NULL}]$\;
\For {$i = 1$ to $N$} {
$\text{Root} \gets TV_1$\;
$i \gets i + 1$\;
\uIf {$TV_i > \textup{Root}$}{
$\text{Root} \gets TV_i$\;}
\uElseIf{$TV_i \leq \textup{Root}$}{
$i \gets i+1$\;}
\Else{
do something interesting\;
}
}
}
\end{algorithm}
\end{document}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18588 次 |
| 最近记录: |