前言

如何在LaTeX当中插入算法伪代码?

可以用两种package来写伪代码:algorithmic,algorithm2e

algorithmic

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm}
    \caption{Sample Algorithm}
    \begin{algorithmic}[1]
        \State $i \gets 1 $
        \While {$ i > 10 $}
        \State statement
        \If{condition}
        \State statement
        \State statement
        \Else
        \State statement
        \EndIf
        \EndWhile
    \end{algorithmic}
\end{algorithm}
\end{document}

algorithm2e

\documentclass{article}
\usepackage{algpseudocode}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

\begin{document}
\begin{algorithm}
    \caption{Sample Algorithm}
    \SetAlgoLined
    \DontPrintSemicolon

    $i \gets 1$ \;
    \While{$i>10$}{
    statement\;
    \eIf{condition}{
        statement\;
        statement\;}
        {statement\;}
    }
\end{algorithm}
\end{document}

Reference