1

I am trying to put figure inside the algorithm environment and also a table. But getting error.

\documentclass[a4paper]{article}

\usepackage[margin=1.5in]{geometry}    % For margin alignment
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
 \usepackage{arevmath}     % For math symbols
 \usepackage[noend]{algpseudocode}

 \title{Algorithm template}
 \author{Moody}

 \date{\today}    % Today's date

 \begin{document}
 \maketitle
 \section{Demo code}

\begin{algorithm}
    \caption{Put your caption here}
    \begin{algorithmic}[1]

        \Procedure{Tom}{$a,b$}       \Comment{This is a test}
        \State System Initialization
        \State Read the value 
        \If{$condition = True$}
        \State Do this
        \If{$Condition \geq 1$}
        \State Do that
        \ElsIf{$Condition \neq 5$}
        \State Do another
        \State Do that as well
        \Else
        \State \includegraphics[scale=1.5]{lion.jpg}

        \EndIf
        \EndIf

        \While{$something \not= 0$}  \Comment{put some comments here}
        \State $var1 \leftarrow var2$  \Comment{another comment}
        \State $var3 \leftarrow var4$
        \EndWhile  \label{roy's loop}
        \EndProcedure

    \end{algorithmic}
 \end{algorithm}

\end{document}
  • What error message do you get? – egreg May 13 at 12:06
1

In your provided MWE, you didn't include the package graphicx, just include that package your MWE works fine for me, and the modified MWE is:

\documentclass[a4paper]{article}

\usepackage[margin=1.5in]{geometry}    % For margin alignment
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
 \usepackage{arevmath}     % For math symbols
 \usepackage[noend]{algpseudocode}
\usepackage{graphicx}

If still the error exists, then please place the error code too...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.