[Tex/LaTex] algorithm2e, if-then-else alignment in output block

algorithm2e

I would like to have an if-then-else statement in the output block, with this MWE:

\documentclass{article}
\usepackage[ruled]{algorithm2e}
\usepackage{amsmath}

\begin{document}
  \begin{algorithm}[H]
    \SetKwInput{Output}{Output}
    \Output{
      \eIf{QP is feasible}{ 
        $x^*$: primal solution of problem (1)\newline
        $\lambda^*$: dual solution solving (2).
      }{
        infeasibility status.
      }
    }
    \caption{QP solver}
  \end{algorithm}

\end{document}

i get the following result:
enter image description here

Is there a way of getting the lines of the if-then-else block aligned with the first if if?

Like this:

enter image description here

Thanks!

Best Answer

If you only want what you show, then you can adjust \algomargin:

enter image description here

\documentclass{article}

\usepackage[ruled]{algorithm2e}
\DontPrintSemicolon

\begin{document}

% Update \algomargin
\settowidth{\algomargin}{\textbf{Output:} }
\addtolength{\algomargin}{\parindent}
\begin{algorithm}[H]
  \makebox[0pt][r]{\textbf{Output:} }%
    \eIf{QP is feasible}{
      $x^*$: primal solution of problem (1)\;
      $\lambda^*$: dual solution solving (2)\;
    }{
      infeasibility status\;
    }
  \caption{QP solver}
\end{algorithm}
\setlength{\algomargin}{\parindent}% Restore \algomargin

\begin{algorithm}[H]
  \SetKwInOut{Output}{Output}
  \Output{\eIf{QP is feasible}{
      $x^*$: primal solution of problem (1)\;
      $\lambda^*$: dual solution solving (2)\;
    }{
      infeasibility status\;
    }}
  \caption{QP solver}
\end{algorithm}

\end{document}

The second algorithm is merely for reference of the alignment.