[Tex/LaTex] Mutliple inputs with line breaking

algorithm2eindentationline-breaking

I am trying to write an algorithm with multiple inputs in algorithm2e.

The result I would like to have is something like

Algorithm
-------------------
Input: Input number 1
       Input number 2
       Input number 3

[Some clever algorithm]

The best I could do yet was one of those two solutions

\begin{algorithm}
\KwIn{Input number 1}
\KwIn{Input number 2\\ Input number 3
\end{algorithm}

which archives

Algorithm
-------------------
Input: Input number 1
Input: Input number 2
Input number 3

Any idea how to get the desired result?

Best Answer

You can define a new command to give you the desired indentation:

\documentclass{article}
\usepackage{algorithm2e}

\newlength\mylen
\newcommand\myinput[1]{%
  \settowidth\mylen{\KwIn{}}%
  \setlength\hangindent{\mylen}%
  \hspace*{\mylen}#1\\}

\begin{document}

\begin{algorithm}
\KwIn{Input number 1}
\myinput{Input number 2}
\myinput{Input number 3 spanning more than one line just as an illustration for the example}
\end{algorithm}

\end{document}

enter image description here