[Tex/LaTex] Algorithmicx multiple statements per line aligned over all lines

algorithmicxalgorithms

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?

Best Answer

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

enter image description here

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