如何在 Latex 中编写类似下图的算法?

如何在 Latex 中编写类似下图的算法?

如何在 Latex 中编写类似下图的算法? 在此处输入图片描述

我执行了这个代码,但是算法的输出并不像上图这样

\usepackage[options ]{algorithm2e}
\begin{algorithm}‎
\SetAlgoLined‎
\SetKwInOut{Step}{Step}
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\Input{The }
\Output{The }‎
\For{Num}{
\Step{Choose}‎
\Step{Choose}
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{To }
\end{algorithm}‎

答案1

\documentclass{article}
\usepackage[ruled]{algorithm2e}

\begin{document}

\begin{algorithm}
\SetAlgoLined
\caption{To} 
\SetKwInOut{Step}{Step}
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\Input{The}
\Output{The}
\For{Num}{
\par\textbf{Step 1:} Choose
\par\textbf{Step 2:} Choose
\par\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\end{algorithm}

\end{document}

在此处输入图片描述

相关内容