# Algorithmicx multiple statements per line aligned over all lines

I would like to put a <- b and e <- f, in parallel on a single line in an algorithmicx environment. I want the same with c <- d and g <- h. Then I want to align both lines. The output shouod look like this.

1.    a <- b            e <- f
2.    c <- d            g <- h


This is the code I have now:

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{Test}{}
\State{$a \gets b$}
\State{$e \gets f$}
\State{$c \gets d$}
\State{$g \gets h$}
\EndProcedure
\end{algorithmic}
\end{algorithm}


Does anyone know how to do this? Could I use the multicolumn environment perhaps?

You can define a new command \BiState which takes two arguments

\newcommand{\BiState}[2]{%
\State{\makebox[2cm]{#1\hfill}#2}%
}


and use it like this

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

\newcommand{\BiState}[2]{%
\State{\makebox[2cm]{#1\hfill}#2}%
}

\begin{document}

\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{Test}{}
\BiState{$a \gets b$}{$e \gets f$}
\BiState{$c \gets d$}{$g \gets h$}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}


Result

Adjust 2cm in its definition to the value that better fits your requirements.

• thanks just what I needed. Your solution works like a charm! – Luc Jan 22 '14 at 15:47

One solution is:

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{Test}{}
\State{$a \gets b \qquad e \gets f$}
\State{$c \gets d \qquad g \gets h$}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}


Output:

• thanks for your suggestion. However, I have many lines in my algorithm. Consequently, this approach will make it very difficult to align all lines. – Luc Jan 22 '14 at 13:17