[Tex/LaTex] Changing indentation of pseudocode including line numbers with algorithm and algorithmic

algorithmsindentationpseudocode

If I have pseudocode as shown below using the algorithm and algorithmic packages, is it possible to indent the pseudocode, including the line numbers, so that it lines up with the indentation of the first line of the paragraph above, i.e. so that the line numbers of the pseudocode are indented as much as the first line of the paragraph above.

enter image description here

Best Answer

This is one possible solution via adjustwidth environment from changepage package. It takes two arguments.

As to the par indention value, please check HERE

\begin{adjustwidth}{left indent}{right indent}
\begin{algorithmic}[1]
content
\end{algorithmic}
\end{adjustwidth}

enter image description here

Code

\documentclass[12,a4paper]{article}
\usepackage[showframe,papersize={\paperwidth,8cm}]{geometry}
\pagestyle{empty}
\usepackage{algorithmic}
\usepackage[plain]{algorithm}
%\usepackage{algpseudocode}
\usepackage{changepage}    %adjustwidth environment from changepage package


\begin{document}

Paragraph text, Paragraph text, Paragraph text, Paragraph text, Paragraph text, Paragraph text, Paragraph text, Paragraph text,

\begin{algorithm}
\begin{adjustwidth}{1em}{}
\begin{algorithmic}[1]
\STATE{\textit{pollingDateTime $\leftarrow$ now $-$ 1 hour}}
\FOR {\textbf{each} rssFeed}
\STATE {\textit{pollingDateTime $\leftarrow$ now $-$ 1 hour}}
\ENDFOR 
\IF {\textit{pollingDateTime is even}}
\STATE {\textit{pollingDateTime $\leftarrow$ now $-$ 1 hour}}
\ENDIF
\end{algorithmic}
\caption{Algorithm 1}\label{alg1}
\end{adjustwidth}
\end{algorithm}
\end{document}