[Tex/LaTex] How to insert algorithm pseudocode in Lyx

algorithmslyx

recently I found LyX is good for writing notes. But I don't know how to add a piece of algorithm pseudocode in Lyx environment. Could you please help give some advice? Thanks!

How could I implement the following algorithmic pseudocode? Could you please give the complete operations on LyX 2.1.1?

enter image description here

Best Answer

I have found the answer:

  1. add the \usepackage{algorithm,algpseudocode} into the premble
  2. insert a algorithm block (Insert --> Floating --> Algorithm)
  3. insert the tex code in the algorithm block (Insert --> Tex Code)
  4. add the following latex code

    \begin{algorithmic}[1]
    \Require{$\rho \geq 1$}
    \Ensure{$X_k$}
    \While{not converged}
    \State{Solve $X_{k+1}=\min_{X} L(X,Y_k, \mu_k)$}
    \State{$Y_{k+1}=Y_k+\mu_k h(X_{k+1})$}
    \State{$\mu_{k+1}=\rho \mu_k$}
    \EndWhile
    \end{algorithmic}
    
Related Question