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?

  • 1
    Doesn't... what? Align? Appear? – TheIncredibleZ1 Mar 21 '17 at 14:45
  • 1
    Welcome to TeX.SE! Please tell us which packages need to be loaded in order to make your code compilable. Please also tell us which document class you use. – Mico Mar 21 '17 at 14:47
  • 3
    In a list, I always put an equation inside a \parbox{\linewidth}, or possibly \hspace*{\dimexpr\linewidth-\textwidth}\parbox{\textwidth}. – John Kormylo Mar 21 '17 at 15:37
  • You might want to read tex.stackexchange.com/questions/503/why-is-preferable-to – user36296 Mar 21 '17 at 16:50
  • 1
    You can really spruce up your code... – Werner Mar 22 '17 at 0:25
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.

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.