1

I am using the algorithm environment and I do not know how to make the lines for the loops under the corresponding word, not where I have them now.

Here is my code:

\documentclass{article}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\usepackage{ragged2e}
\SetKwInOut{Parameters}{Parameters}

\begin{document}
\begin{algorithm}[htb]
    \DontPrintSemicolon 
    \justifying 
    \caption{The caption}
    \KwData{Some data}
    \Parameters{a,b}
    \KwResult{Result}
    \For{something or other}{
        This is some random text \;
        Some more text\;    
    }   
    More text here
\end{algorithm}
\end{document}

I am getting the following:

enter image description here

How can I fix the problem? I want the line to appear right under for.

Thanks, any suggestion will be appreciated.

1 Answer 1

0

Remove \justifying from within the algorithm environment:

enter image description here

\documentclass{article}

\usepackage[ruled,vlined,linesnumbered]{algorithm2e}

\SetKwInOut{Parameters}{Parameters}

\begin{document}

\begin{algorithm}[htb]
  \DontPrintSemicolon 
  \caption{An algorithm}
  \KwData{Some data}
  \Parameters{$a, b$}
  \KwResult{Result}
  \For{something or other}{
    This is some random text\;
    Some more text\;    
  }   
  More text here
\end{algorithm}

\end{document}
3
  • I need something to keep the lines justified as I have some long lines, how would one do that? Commented Oct 17, 2020 at 11:00
  • @PereGarauBurguera: If you have a long line, you can place it inside a [t]op-aligned \parbox of appropriate width (\linewidth minus the indentation) within which you can place the text (it should naturally be justified). Here is an example (output). Commented Oct 17, 2020 at 21:29
  • Thanks, that solved it! Commented Oct 19, 2020 at 7:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.