3

I have the following code for printing out an algorithm

enter image description here

However, I would like to have Input and Output before the For Loop.

E.g. Input: ingredients I = (1, \ldots, N), Output: Pizza

Is there an elegant solution for this?

\documentclass[12pt]{beamer}
\usepackage{algorithm,algorithmic}

\begin{document}

\begin{frame}

\begin{algorithm}[H]
\begin{algorithmic}[1]
\FOR{$j=1$ to $N$}
\STATE Add Pineapple on Pizza
\ENDFOR
\end{algorithmic}
\caption{pseudocode for making a pizza}
\label{alg:seq}
\end{algorithm}
\end{frame}

\end{document}

1 Answer 1

8

Something like this?

\documentclass[12pt]{beamer}
\usepackage{algorithm,algorithmic}

\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

\begin{document}

\begin{frame}

\begin{algorithm}[H]
\begin{algorithmic}[1]
\REQUIRE ingredients I = (1, \ldots, N)
\ENSURE not Pizza 
\FOR{$j=1$ to $N$}
\STATE Add Pineapple on Pizza
\ENDFOR
\end{algorithmic}
\caption{pseudocode for not making a pizza}
\label{alg:seq}
\end{algorithm}
\end{frame}

\end{document}

enter image description here

3
  • Sorry I need the output tag to be Pizza, it is crucial for my presentation. Any way to adjust it?
    – Fraïssé
    Dec 3, 2017 at 22:40
  • @CarlosDanger I am not sure I understand your comment Dec 3, 2017 at 22:44
  • +1, much better this way!
    – CarLaTeX
    Dec 4, 2017 at 5:42

You must log in to answer this question.

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