# How to align input arguments of an algorithm in a grid?

I'm writing an algorithm box using algorithm2e and want to align the input arguments in a grid. I got close to the desired layout using two tabular environments, each inside of a minipage.

However, I would like both the word "Input:" and the two tables to align at the top instead of being vertically centered. Moreover, I would like to reduce the column and row spacing but putting \setlength{\tabcolsep}{.5em}% and \renewcommand{\arraystretch}{1.5}% inside the table does not have any effect. How can this be done?

\usepackage[linesnumbered,ruled,noend]{algorithm2e}
\begin{algorithm}[h!]
\SetEndCharOfAlgoLine{}
\SetKwInOut{Input}{Input}
\Input{
\begin{minipage}{0.4\textwidth}
\begin{tabular}{ll}
$A$ & Description \\
$B$ & Description \\
$C$ & Description \\
$D$ & Description \\
\end{tabular}
\end{minipage}\hfill
\begin{minipage}{0.4\textwidth}
\begin{tabular}{ll}
$E$ & Description \\
$F$ & Description \\
$G$ & Description \\
\end{tabular}
\end{minipage}\hfill
}
\BlankLine
Initialize variables.
\For{all steps}{
\Comment{Do something.}
}
\Return{The result.}
\BlankLine
\caption{Algorithm caption.}
\end{algorithm}


You don't need to use a minipage for this. Just assign a [t]op anchor for the tabulars:

\documentclass{article}

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

\SetEndCharOfAlgoLine{}
\SetKwInOut{Input}{Input}

\begin{document}

\begin{algorithm}
\Input{%
\begin{tabular}[t]{ll}
$A$ & Description \\
$B$ & Description \\
$C$ & Description \\
$D$ & Description
\begin{tabular}[t]{ll}
$E$ & Description \\
$F$ & Description \\
$G$ & Description
\end{tabular}
}
\BlankLine
Initialize variables\;
\For{all steps}{
Do something\;
}
\caption{Algorithm caption.}
\end{algorithm}

\end{document}


If you want the item and description to be closer to one another, adjust the column spacing:

\begin{tabular}[t]{l @{\hspace{.5em}} l}
% ...
\end{tabular}


The @{...} column specification is used to adjust the inter-column spacing between two consecutive columns.

• Thanks, this was very fast and a nice solution. I also added comment signs (\end{tabular}%) to avoid extra spaces. – danijar Jan 21 at 19:55