# Algorithm writing in latex

How can I write this algorithm in left align latex of 2 column? I have tried this but its not working

    \textit{repeat till convergence}
\begin{equation}\small
\label{eq_04}
{
W_{i+1} = W_i - \alpha \frac{\partial}{\partial W_i}f(W_i)
}
\end{equation} ## 1 Answer

(Remark: I updated this answer completely after the OP provided more information about formatting requirements.)

The following solution works by setting up a dedicated environment called myalgo. The "outer" equation environment assures that there's some vertical separation between the algo material and the text above and below it, and it also provides an equation number. The "inner" minipage environment, whose width is set to 0.9\columnwidth, assures that each line starts flush-left within the minipage. Instances of myalg may be cross-referenced via the usual \label-\ref mechanism. \documentclass[twocolumn]{article}
\newenvironment{myalgo}{%
\begin{equation}\begin{minipage}{0.9\columnwidth}\obeylines}{%
\end{minipage}\end{equation}}

\begin{document}
\noindent
Generally, for a simple supervised learning the \dots
\begin{myalgo} \label{alg:1}
\qquad\textit{repeat until convergence}
\{
$\displaystyle W_{i+1} = W_i - \alpha \frac{\partial}{\partial W_i} f(W_i)$
\}
\end{myalgo}
Here $W_i$ are network parameters of each \dots

A cross-reference to algorithm \ref{alg:1}.
\end{document}

• Thanks. its coming in the middle. However, i want it to be left align in two column article. Also, the equation number is number coming with this – Aadnan Farooq A May 14 '19 at 8:18
• @AadnanFarooqA - Please edit your posting to state all of your formatting requirements up front. How was I supposed to know that you use a two-column layout? – Mico May 14 '19 at 8:23
• please do accept my apology, i have updated my question – Aadnan Farooq A May 14 '19 at 8:27