[Tex/LaTex] Listing source code in two columns

listingssourcecode

I’ve come across a document typeset in LaTeX which solves code listings in a way that I would be very happy to do in my document, but I can’t figure out how the author managed to do this in LaTeX.
Does anyone know how one can list code in two columns as done in the example below, which package is used?

enter image description here

Best Answer

The example is generated by using the fancyvrb package. You can put the codes in two minipages and mimic a two column layout. Also note that the line numbers are somewhat misplaced; a solution is attached below.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{zlmtt}
\usepackage{fancyvrb}

\begin{document}

\noindent
\begin{minipage}{0.49\linewidth}
\begin{Verbatim}[frame=topline,numbers=left,label=Original Code,framesep=3mm]
class C {
  public X x = new X();

  public void f() {
  ...
  }
}
\end{Verbatim}
\end{minipage}\hfill
\begin{minipage}{0.49\linewidth}
\begin{Verbatim}[frame=topline,numbers=left,label=After Extract Local,framesep=3mm]
class c {
  public X x = new X();

  public void f(){
  ...
  }
}
\end{Verbatim}
\end{minipage}

\par\vspace{3ex}

\noindent
\begin{minipage}{0.49\linewidth}
\begin{Verbatim}[frame=topline,numbers=right,label=Original Code,framesep=3mm,numbersep=-4pt]
class C {
  public X x = new X();

  public void f() {
  ...
  }
}
\end{Verbatim}
\end{minipage}\hfill
\begin{minipage}{0.49\linewidth}
\begin{Verbatim}[frame=topline,numbers=right,label=After Extract Local,framesep=3mm,numbersep=-4pt]
class c {
  public X x = new X();

  public void f(){
  ...
  }
}
\end{Verbatim}
\end{minipage}

\end{document}

enter image description here

Related Question