2

I would like to write pseudo code algorithm in Latex as in the attached picture.I have written code to make just like above algorithm but its not working for me. Is this code correct...

enter image description here

\IncMargin{1em}
 \begin{algorithm}
\SetKwInOut{Part 1}{input}
\SetKwInOut{Part 2}{output}
\Part 1{}
\BlankLine
\emph{abcdefgh $D$ ijklmnop}\;
\emph{ abcdefgh $A$}\;
\For{$k\leftarrow 1$ \KwTo $M$}{
            \For {each $m$ $ ∈ $ {1, 2, …, J}{
                \emph{ abcdefgh $D$}\;
                \emph{abcdef }\;
}
\Part 2{}
\emph{abcdefgh $A$ ijklmnop}\;
\emph{ abcdefgh $A$}\;
\For {each $m$ $ ∈ $ {1, 2, …, J}{
\emph{ abcdefgh $D$}\;
\emph{abcdef }\;
\emph{abcdef }\;
}
}
\For{$k\leftarrow 1$ \KwTo $M$}{
\emph{ abcdefghklmop}\;
\emph{ abcdefghklmop}\;
\emph{ abcdefghklmop}\;
}
\caption { Algorithm Sample}
\end{algorithm}
 \DecMargin{1em}
2
  • Duplicate of tex.stackexchange.com/q/359729/110998 Commented Mar 22, 2017 at 9:49
  • Have a look at LaTeX/Algorithms Copy some working sample code from this forum or from somewhere else from the internet and start modifying it. If you get stuck, post the code here and ask specific questions. Commented Mar 22, 2017 at 9:57

1 Answer 1

1

The following is more in line with the regular syntax of algorithm2e:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage[ruled,vlined]{algorithm2e}
\DontPrintSemicolon
\newcommand{\To}{\mbox{\upshape\bfseries to}}

\begin{document}

\begin{algorithm}
  \caption{Algorithm sample}
  \textbf{Part 1}\;
  \nl abcdefgh $\{ D_i \}_{i = 1}^M$ ijklmnop\;
  \nl abcdefgh $A_m$\;
  \nl \For{$K = 1$ \To{} $M$}{%
    \ForEach{$m \in \{1, 2, \dots, J\}$}{
      abcdefgh $\{ D \}_m^t$\;
      abcdefgh\;
    }
    \textbf{Part 2}\;
    abcdefgh $\{ G_i \}_{i = 1}^K$\;
    abcdefgh $D_m$\;
    \ForEach{$m \in \{1, 2, \dots, J\}$}{
      abcdefgh $\{ G \}_m^y$\;
      abcdefgh\;
      abcdefgh\;
    }
  }
  \nl \For{$K = 1$ \To{} $M$}{
    abcdefghijklmno\;
    abcdefghijklmno\;
    abcdefghijklmno\;
  }
\end{algorithm}

\end{document}
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.