# Using lstlistings in two columns

My goal is to display source code (awk, Python, R and SAS) and text (their output) side-by-side. Both are loaded from external files, and can be pretty long sometimes (pagebreaking is inevitable), the source code should be syntax highlighted. The source code should stay on the left side, and the output should stay on the right side, even if there is a pagebreak.

I'm using the listings package for its syntax highlighting.

I can't find an environment to behave right when there's a pagebreak.

Some of what I've tried already:

1. multicols: this environment is fine, until there's a pagebreak (left side breaks to the right side and messes up everything)
2. minipage: no pagebreak yet
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Marco Daniel Sep 17 '13 at 10:00
• Thanks for the quick response, but I'm a little confused about the "duplicate" reference... My source code is not LaTeX (it's awk). So I guess the referenced article does not answer my question...But, I've just found this one with three suggestions. But they mess up the style of the listings. – masu Sep 17 '13 at 14:57
• I've just solved the problem using the paracol package/environment. It messed up the background coloring and the border of the listing whenever linebreaks occured. I ommitted these features from the listing and done the coloring and bordering with mdframed... now it is fine. – masu Sep 17 '13 at 16:49

I have finally solved my problem (as I mentioned it in a comment) using the paracol environment.

\documentclass{minimal}
\usepackage{paracol}
\begin{document}
\begin{paracol}{2}
Left
\switchcolumn
Right
\end{paracol}
\end{document}


Still, the background coloring needed some patching up. I've replaced the listing background using the mdframed package.

So the final MWE has come to this:

\documentclass{minimal}

\usepackage{paracol}
\usepackage{listings}
\usepackage[framemethod=TikZ]{mdframed}

\lstnewenvironment{code}{
\mdframed[outerlinecolor=black, backgroundcolor=gray]{}
}{
\endmdframed
}

\begin{document}

\begin{paracol}{2}
\begin{code}
Left
\end{code}
\switchcolumn
\begin{code}
Right
\end{code}
\end{paracol}

\end{document}


However, this also generates some warnings (multiply defined labels in mdframed), I've made a patch for this, and asked here whether there is a better solution.