0

Below is a MWE consisting of two small algorithms demonstrating how the unnecessary use of {...} environment can cause unexpected behavior from LaTeX, i.e., overwriting line number as shown in the second algorithm.

enter image description here

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

\begin{document}

\begin{algorithm}
\caption{Algorithm 1}
\label{Algorithm:Alg1}
\begin{algorithmic}[1]
\Function {Algorithm1}{}
\If{Condition 1}
    \State Statement 1
\Else
    \State Statement 2
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{Algorithm 2}
\label{Algorithm:Alg2}
\begin{algorithmic}[1]
\Function {Algorithm2}{}
\If{Condition 1}
    \State Statement 1
\Else
{
    \State Statement 2
}
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}
  • 2
    We can understand your requirement. Please add MWE (minimal working example) to check further. – Saravanan Dec 6 '18 at 4:26
  • After the change introducing a MWE this does not seem to be a question anymore. – epR8GaYuh Dec 6 '18 at 6:17
  • Right. It still carries knowledge to be shared. If such "questions" are not permitted here, I am fine to have it removed. – Abdullah Heyari Dec 6 '18 at 6:35
  • 1
    You may convert it into a question again and add an answer by yourself. – epR8GaYuh Dec 6 '18 at 14:50

Your Answer

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

Browse other questions tagged or ask your own question.