# indentation of long lines in algorithm2e and vertical spacing problem

After spending 2 hrs on this and trying all sorts of things, I give up. I am using algorithm2e and when I have long description lines, the new line gets shifted a little to the right. Also, even though I add new empty line between two paragraphs, no empty line shows up in the output.

First, here is diagram of the problem, with the code that generated it below

Code is

\documentclass[12pt]{article}

\usepackage{algorithm2e}
\DontPrintSemicolon
\usepackage{algpseudocode}

\usepackage{amsmath}
\pagestyle{empty}
\setlength{\parindent}{0pt}

\begin{document}

\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\Input{$y'=f(x,y)$}
Assume expansion around $x_0$ with initial conditions $y(x_0)=y_0$

\eIf{$f(x,y)$ analytic at $x_0$}
{
Very long description here. very long description here. very long
description here. very long description here. Let\;

\begin{align*}
y &= y_0 + \sum_{n=0}^{\infty}  \frac{ x^{n+1}}{(n+1)!}  \, F_n(x,y)  \bigg\vert_{\substack{x=x_0\\y=y_0}}
\end{align*}

more very long description here. very long description here.
very long description here. very long description here.\;

How to add paragraph spacing above this line?
}
{
\eIf{ $f(x,y)$ not linear in $y(x)$}
{
\textbf{return}  \texttt{-{}-}     Not supported\;
}
{
And so on
}
}

\end{algorithm}

\end{document}


Compiled with lualatex in TL 2023.

I tried replacing \; by \\ but this had no effect. I also tried adding \raggedright but this had no effect.

I looked and tried many other things from somewhat related question but not able to figure how to correct this.

I could force the vertical spacing between paragraphs by using \vspace like this new MWE below. So this fixes the paragraph spacing, but the initial shift on long lines still there

\documentclass[12pt]{article}

\usepackage{algorithm2e}
\DontPrintSemicolon
\usepackage{algpseudocode}

\usepackage{amsmath}
\pagestyle{empty}
\setlength{\parindent}{0pt}

\begin{document}

\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\Input{$y'=f(x,y)$}
Assume expansion around $x_0$ with initial conditions $y(x_0)=y_0$

\eIf{$f(x,y)$ analytic at $x_0$}
{
Very long description here. very long description here. very long
description here. very long description here. Let\;
%
\begin{align*}
y &= y_0 + \sum_{n=0}^{\infty}  \frac{ x^{n+1}}{(n+1)!}  \, F_n(x,y)  \bigg\vert_{\substack{x=x_0\\y=y_0}}
\end{align*}
%
more very long description here. very long description here.
very long description here. very long description here.\;

\vspace{6pt}
How to add paragraph spacing above this line?
}
{
\eIf{ $f(x,y)$ not linear in $y(x)$}
{
\textbf{return}  \texttt{-{}-}     Not supported\;
}
{
And so on
}
}

\end{algorithm}

\end{document}


The question is: How to make long lines that wrap all start left aligned with no shift. And if using \vspace to force space between paragraphs is the correct solution?

Algorithms are set in the same way that regular paragraphs are. So, if you want to have some form of gap between statements, you'll have to force it somehow. So, use some form of \vspace for this. Below I use \medskip.

The other horizontal misalignment you see in wide statements (paragraphs) that wrap is caused by the hanging indent. You can remove this by adding \SetAlgoHangIndent{0pt} to your preamble.

\documentclass[12pt]{article}

\usepackage{algorithm2e}
\DontPrintSemicolon
\SetAlgoHangIndent{0pt}

\usepackage{amsmath}

\begin{document}

\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\Input{$y' = f(x, y)$}
Assume expansion around $x_0$ with initial conditions $y(x_0) = y_0$

\eIf{$f(x, y)$ analytic at $x_0$}{%
Very long description here. very long description here. very long
description here. very long description here. Let
$y = y_0 + \sum_{n = 0}^{\infty} \frac{x^{n + 1}}{(n + 1)!} \, F_n(x,y) \biggr\rvert_{\substack{x = x_0 \\ y = y_0}}$
more very long description here. very long description here.
very long description here. very long description here.\;

\medskip

How to add paragraph spacing above this line?\;
}{
\eIf{$f(x, y)$ not linear in $y(x)$}{%
\textbf{return} \texttt{-{}-} Not supported\;
}{%
And so on
}
}
\end{algorithm}

\end{document}