# Align the word input of algorithm2e with a tabularx table

I'm referring to this post. I like the idea from 'a different ben' of the tabularx table inside the \Input command. But I would like to have the word Input: at the top, on the same line as the first row of the table. The suggested \newline in the linked post doesn't work for me.

MWE:

\documentclass{scrbook}
\usepackage{tabularx}
\usepackage[ruled,longend,german,algochapter]{algorithm2e}
\usepackage{lipsum}

\begin{document}
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption[Description]{Description}
\Input{\begin{tabularx}{\textwidth}{p{.03\textwidth}p{.03\textwidth}X}
$a$ &   -- &    Desc1   \\
$b$ &   -- &    Desc2   \\
$c$ &   -- &    Desc3
\end{tabularx}
}
\end{algorithm}
\end{document}

-

You have to use [t] for setting the vertical alignment; however, your tabular will be too wide.

\documentclass[draft]{scrbook}

\usepackage[pass,showframe]{geometry} % just to show the margins

\usepackage{tabularx,calc}
\usepackage[ruled,longend,german,algochapter]{algorithm2e}
\usepackage{lipsum}

\newenvironment{algotabularx}
{\tabularx{\linewidth-\inoutsize-\widthof{~~~}-4\tabcolsep-\rightskip}[t]}
{\endtabularx}

\begin{document}

\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption[Description]{Description}
\Input{Something to show the alignment}
\Input{%
\begin{algotabularx}{@{}p{.03\textwidth}p{.03\textwidth}X@{}}
$a$ &   -- &    \lipsum*[2]  \\
$b$ &   -- &    Desc2   \\
$c$ &   -- &    Desc3
\end{algotabularx}%
}
\Output{Something else}
\end{algorithm}
\end{document}


-
Great, I didn't notice that the text will go over the right side, it was too short in my example. – user2653422 Jul 11 '14 at 14:38
\documentclass{scrbook}
\usepackage{tabularx}
\usepackage[ruled,longend,german,algochapter]{algorithm2e}
\usepackage{lipsum}

\begin{document}
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption[Description]{Description}
\Input{\begin{tabularx}{\textwidth}[t]{p{.03\textwidth}p{.03\textwidth}X}
%%%
%%%
%%%
$a$ &   -- &    Desc1   \\
$b$ &   -- &    Desc2   \\
$c$ &   -- &    Desc3
\end{tabularx}
}
\end{algorithm}
\end{document}

-
Thanks :), I tried \begin{tabularx}[t]{\textwidth}{p{.03\textwidth}p{.03\textwidth}X} but that gave me dozen of errors. I didn't realize that the [t] needs to be after the second curly braces pair. – user2653422 Jul 11 '14 at 14:18
This does cause an overfull \hbox though... – Werner Jul 11 '14 at 14:19
@Werner yes I just answered the question, not the next one:-) – David Carlisle Jul 11 '14 at 14:57