0

I want to insert a simple pseudo code as follows, but I confront with an error and I am not able to resolve it.

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

\begin{document}

\begin{algorithm}
\begin{algorithmic}[1]
\State $i \gets 1$
\While {$i > 10$}
\State Statement
\EndWhile
\end{algorithmicx}
\end{algorithm}

\end{document} 

enter image description here

Note that I am using WinEdt 10.3 to compile my codes.

=======================================================

UPDATE:

I have modified my initial code based on the comment of a user and try to compile the following .tex file, but I still have a problem.

TeX file: https://1drv.ms/u/s!AsOHKyT9kjJO2T5_jgHT_niDnnmB

Error log: https://1drv.ms/t/s!AsOHKyT9kjJO2T0cTrj7E1Qe4gFX

It is worth mentioning that its MWE is also as like as follows:

\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
\caption{My algorithm}\label{a1}
\begin{algorithmic}[1]
\State $i \gets 1$
\While {$i > 10$}
\State Statement
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document} 
1

Just remove algorithmic package and the other corresponding preamble, you would be good to go.

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

\begin{document}

        \begin{algorithmic}[1]
            \State $i \gets 1$
            \While {$i > 10$}
            \State Statement
            \EndWhile
        \end{algorithmic}

\end{document} 

this would give you:

enter image description here

If you want to add labels and captions to this, just add insert the above-mentioned snippet within algorithmic environment into algorithm environment,

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

\begin{document}
\begin{algorithm}
    \caption{My algorithm}\label{a1}
        \begin{algorithmic}[1]
            \State $i \gets 1$
            \While {$i > 10$}
            \State Statement
            \EndWhile
        \end{algorithmic}
\end{algorithm}
\end{document} 

this would give you:

enter image description here

  • Copying and pasting the first code you have provided, I could properly compile the algorithm and get the output of it. But when it comes to the second code (with the caption), I face the following errors: ibb.co/g609pyw. Please help me to resolve this problem too. Many thanks in advance. – Moosavi_69 Jan 25 at 8:09
  • @Moosavi_69 Your log reads that for some reason, your caption sits outside the floating environment. May be if you post the problematic MWE, I can look into that for you ;) – Raaja Jan 25 at 8:25
  • Thanks for the reply. I do not exactly know what do you mean by MWE. But I have provided the .tex file that I compile and the log of errors that I encounter. [TeX file] (ufile.io/wulab) and [error log] (ufile.io/16471). I look forward to your kind helps. – Moosavi_69 Jan 25 at 8:39
  • Please don't provide external unsecure links, could you update the .tex file in your question? For MWE have a look here: tex.meta.stackexchange.com/questions/228/… – Raaja Jan 25 at 8:45
  • 1
    I eliminated the .aux file, and instead of downloading packages from the internet, I allowed WinEdt to install the required packages. It now works. Many thanks. – Moosavi_69 Jan 25 at 9:49

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.