I am brand new to LaTeX, and am trying to create a short pseudo code section for a paper. The current issue I'm facing is that line numbers (and vertical alignment in general) is off for many lines.
Here is the code I currently have (I am using Texmaker on Linux for compiling).
\documentclass{article}
\usepackage{amsmath}
\usepackage[linesnumbered, ruled]{algorithm2e}
\usepackage[noend]{algpseudocode}
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{document}
{\SetAlgoNoLine
\begin{algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\caption{Leak Detection}
\begin{algorithmic}[1]
\Require{Set $C$ of all observations of interest}
\Ensure{Set $leaks$ of all identified $CH_{4}$ leak polygons}
\State $ $
\ForEach{record $c_{i}$ in $C$}{
\State $\textit{movingAvg} \gets \textit{avg. $CH_{4}$ for past 2
min.}$
\State $\textit{movingSD} \gets \textit{SD of $CH_{4}$ for past 2
min.}$
\State $\textit{movingThreshold} \gets \max(1 SD > movingAvg, 10\% >
movingAvg)$
\If {$CH_{4} level of c_{i} > movingThreshold$}{
\State $\textit{flag $c_{i}$ as elevated}$
\State $\textit{buffer $c_{i}$ location with 20m radius}$
}
}
\State $leaks \gets \textit{merge of all intersecting $c_{i}$
buffers}$
\State $ $
\ForEach{Polygon $p \in leaks$}{
\State $\textit{mark centroid of p}$
}
\Return $leaks$
\end{algorithmic}
\end{algorithm}}
\end{document}
And the output looks like this:
I cannot figure out why none of the lines in the foreach sections are not indented,and also why the line numbers are not cleanly lined up with each other.
I am trying to get lines 2-6 indented inside the first foreach, and line 9 indented within the second foreach. The final return statement is not supposed to be indented, but it is. What am I missing here?

