Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Inserting an algorithm in LaTeX

📅 2012-Jun-29 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ algorithm, latex ⬩ 📚 Archive

A simple algorithm in LaTeX
A simple algorithm in LaTeX

One of the simple and beautiful ways to insert algorithms or procedures into a LaTeX document is using the algorithmicx package. The simple example given below generated the above figure. For more control structures and configurations check out the package documentation.

% Add the packages

% Insert the algorithm
\caption{Compute sum of integers in array}
    \State $sum = 0$
    \For {each integer $i$ in $A$}
        \State $sum = sum + i$
    \State Return $sum$

Tried with: MikTeX 2.9 on Windows 7 64-bit