4

I want describe an algorithm, and that's why I wanted to use the algorithm package, but the algorithm that I define does not involve of pseudocode. Instead it has more steps and math formulas, so I want to describe it as stages using itemize, and write normal text and some math equations inside the algorithm. I started with something like this, assuming it is valid, but it gives errors.

\documentclass[a4paper]{paper}

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
    \caption{MyAlgo}
    \begin{algorithmic}
        \begin{itemize}
            \item \textbf{Parameters:} $n, t \in \mathbb{N}$, where $t < n$.
        \end{itemize}
    \end{algorithmic}
\end{algorithm}

\end{document}

Any ideas how can I add itemize, and some math stuff inside an algorithm?

1 Answer 1

5

algorithmic is actually a list, so I'd suggest one of two options. First, use the functionality of algorithmicx by setting your "stage headings" manually:

enter image description here

\documentclass{article}

\usepackage{amsfonts}
\usepackage{algorithm,algpseudocode}

\begin{document}

\begin{algorithm}
  \caption{MyAlgo}
  \begin{algorithmic}[1]
    \Statex \textbullet~\textbf{Parameters:} $n, t \in \mathbb{N}$, where $t < n$.
    \State First step
    \State Second step
    \State \ldots
  \end{algorithmic}
\end{algorithm}

\end{document}

You don't have to number the lines. I just used \begin{algorithmic}[1] to do so.

Second, remove the algorithmic environment altogether:

enter image description here

\documentclass{article}

\usepackage{amsfonts}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}
  \caption{MyAlgo}
  \begin{itemize}
    \item \textbf{Parameters:} $n, t \in \mathbb{N}$, where $t < n$.
    \item First step
    \item Second step
    \item \ldots
  \end{itemize}
\end{algorithm}

\end{document}

Note, not algpseudocode required in the second option.

2
  • Thank you for the answer. The second option seems closer to what I actually want. Though, is there any way to push the bullet points to the far left, beginning of the algorithm block?
    – typos
    Jan 11, 2017 at 17:46
  • 1
    @typos: Yes, load enumitem in your preamble and use \begin{itemize}[leftmargin=*].
    – Werner
    Jan 11, 2017 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .