5

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

1
  • did you try a tabular environment ? how about a minipage with multicols ?
    – Elad Den
    Jul 31, 2016 at 12:28

1 Answer 1

9

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .