1

I use the algorithm environment for not only pseudocode but also to be consistent with anything that requires a recipe list of steps. In the below MWE, I create an algorithm environment and I want the first few lines to be plain text. So far so good, and the line wrap seems to follow the margins well, but when the line wraps to the second line, it has a weird indentation.

Second, in the enumerate environment, the text of each item seems to impose a margin that is not consistent with that of the plain text.

My code is:

\documentclass[11pt, oneside]{article}
\usepackage[ruled,vlined]{algorithm2e}

\begin{document}
    \begin{algorithm}
        \footnotesize
        Here I have some text that I need to have within the algorithm that 
        sets up the problem, and the text stretches over two  lines. 
        \textbf{Note that the second line has a weird indentation.}
        \BlankLine
        For all the of the seconds in the day:
        \begin{enumerate}
            \item This is a very long line that briefly describes the 
            computation I am going to use. \textbf{The margin for some 
            reason is different than the text above!}
            $$ {\omega}_{ik} = 42$$
            where $\omega$ and all these Greek letters mean nothing since
            this is just a MWE, but again note that the text does not end at
            the same spot as the first block of text in the environment.
        \end{enumerate}
        \caption{\footnotesize My Little Algorithm}
    \end{algorithm}
\end{document}  

enter image description here

2

I propose you tu use minipage environment as follows to introduce an environment dedicated to text.

\documentclass[11pt, oneside]{article}
\usepackage[ruled,vlined]{algorithm2e}

\begin{document}
    \begin{algorithm}
        \footnotesize
        \begin{minipage}{.92\linewidth}
        Here I have some text that I need to have within the algorithm that 
        sets up the problem, and the text stretches over two  lines. 
        \textbf{Note that the second line has a weird indentation.}
        \BlankLine
        For all the of the seconds in the day:
        \begin{enumerate}
            \item This is a very long line that briefly describes the 
            computation I am going to use. \textbf{The margin for some 
            reason is different than the text above!}
            $$ {\omega}_{ik} = 42$$
            where $\omega$ and all these Greek letters mean nothing since
            this is just a MWE, but again note that the text does not end at
            the same spot as the first block of text in the environment.
        \end{enumerate}
        \end{minipage}
        \caption{\footnotesize My Little Algorithm}
    \end{algorithm}
\end{document} 

Result

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.