0

I have the following problem: the equation in the algorithm doesn't in the middle of algorithm, how can I forward the equation, the code is as follows:

\begin{algorithm}[H]
\SetKwFor{KWHILE}{for}{do}{endfor}
    \caption{algorithm }
    \label{algo1} %
    \KWHILE{stop condition}{    
    \begin{enumerate}[(a)]
        \item sparse coding:problem$$\underset{{{\mathbf{x}}_{i}}}{\mathop{\min }}\,\left\| {{\mathbf{y}}_{i}}-{{\mathbf{D}}^{\left( J-1 \right)}}{{\mathbf{x}}_{i}} \right\|_{2}^{2}\ \ \ \ s.t.\ \ \ {{\left\| {{\mathbf{x}}_{i}} \right\|}_{0}}\le s$$ \\
        \item dictionary update:...
    \end{enumerate}}
\end{algorithm}

Can anyone help me with this?

Troy
  • 13,741

1 Answers1

1

Not an answer.

I tried to guess what packages you use:

\documentclass{article}

% Show layout borders
\usepackage{showframe}

% \SetKwFor
\usepackage[boxed]{algorithm2e}

% \begin{enumerate}[(a)]
\usepackage{enumerate}

% \underset
\usepackage{mathtools}

\begin{document}

\section*{Your Code}

\begin{algorithm}[H]
\SetKwFor{KWHILE}{for}{do}{endfor}
    \caption{algorithm }
    \label{algo1} %
    \KWHILE{stop condition}{    
    \begin{enumerate}[(a)]
        \item sparse coding:problem
        $$
        \underset{{{\mathbf{x}}_{i}}}{\mathop{\min }}\,\left\| {{\mathbf{y}}_{i}}-{{\mathbf{D}}^{\left( J-1 \right)}}{{\mathbf{x}}_{i}} \right\|_{2}^{2}\ \ \ \ s.t.\ \ \ {{\left\| {{\mathbf{x}}_{i}} \right\|}_{0}}\le s
        $$
        \item dictionary update:...
    \end{enumerate}
    }
\end{algorithm}

\section*{Just the Equation}

        $$
        \underset{{{\mathbf{x}}_{i}}}{\mathop{\min }}\,\left\| {{\mathbf{y}}_{i}}-{{\mathbf{D}}^{\left( J-1 \right)}}{{\mathbf{x}}_{i}} \right\|_{2}^{2}\ \ \ \ s.t.\ \ \ {{\left\| {{\mathbf{x}}_{i}} \right\|}_{0}}\le s
        $$

\section*{enumerate and Equation}

    \begin{enumerate}[(a)]
    \item sparse coding:problem
    $$
        \underset{{{\mathbf{x}}_{i}}}{\mathop{\min }}\,\left\| {{\mathbf{y}}_{i}}-{{\mathbf{D}}^{\left( J-1 \right)}}{{\mathbf{x}}_{i}} \right\|_{2}^{2}\ \ \ \ s.t.\ \ \ {{\left\| {{\mathbf{x}}_{i}} \right\|}_{0}}\le s
    $$
    \item dictionary update:...
    \end{enumerate}

\end{document}

enter image description here

  • Please indicate where the middle of the equation should be? (copy the picture above to your computer and use the software paint or similar or a pen if necessary)
  • I also deleted \\ in the equation.