1

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

  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Sep 7 '14 at 4:33
1

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}
|improve this answer|||||
  • @MrMorgan, glad it helps. – Jesse Sep 7 '14 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.