# Two column Algorithmicx with variable-width columns

In another post, @Jubobs suggested to use the multicol package around an algorithmic environment, to typeset the algorithm in two columns.

Recently, I faced a rather aesthetic issue: It might be the case that one column has a long line, while all lines in the other column are short. Example:

Here's the code for the above picture:

\documentclass[twocolumn]{article}
\usepackage[width=11cm]{geometry}   % page width is reduced to show the effect
\usepackage{multicol}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
\begin{algorithm*}[t]
\caption{An algorithm with a long line.}
\label{alg1}
\begin{multicols}{2}
\begin{algorithmic}[1]
\If{$(x = y^2+1$ and $z=x^3+4y -12)$ }
\State $a \gets b + c$
\EndIf

\columnbreak

\State $x \gets 0$
\end{algorithmic}
\end{multicols}
\end{algorithm*}

\end{document}


Is it possible to typeset an Algorithmicx environment in two columns, but with unequal widths? I tried the vwcol package as suggested in this post, but I wasn't able to make it work for my case.

Would this be what you seek? The proposed solution uses varwidth package. Since algorithmic environment is wrapped inside the varwidth, algostore and algorestore is used to continue the numbering.

Note the xx\linewidth can be used to change the width of varwidth

Code:

\documentclass[twocolumn]{article}
\usepackage[width=11cm]{geometry}   % page width is reduced to show the effect
\usepackage{varwidth}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
%
\begin{algorithm*}[t]
\caption{An algorithm with a long line.}
\label{alg1}
\begin{varwidth}[t]{0.45\textwidth}        % change 0.45 to suit your need
\begin{algorithmic}[1]
\If{$(x = y^2+1$ and $z=x^3+4y -12)$ }
\State $a \gets b + c$
\EndIf
\algstore{myalg}
\end{algorithmic}
\State $x \gets 0$

• You can set simply \textwidth in both varwidth. The width is determined by its contents. I think this is what the OP wants. – karlkoeller Feb 9 '14 at 8:33