Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
Works fantastic. Thank's a lot! – Thilo Jul 21 '12 at 18:58
\SetKwInOut{Input}{input}  
\Input{a\\
b\\
c  
}

works fine

share|improve this answer
4  
Welcome to TeX.sx! This is a good to suggestion. To help future visitors please make this in to a complete minimal working example (MWE), cf. Gonzalo Medina's answer. – Andrew Swann Apr 25 at 8:11

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer: please explain why you're recommending it as a solution. Answers that don't explain anything will be deleted. See Good Subjective, Bad Subjective for more information.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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