24

I would like to have two listings, side by side.

They have approximately the same length, therefore I don't care about how it's layed out if one part is longer.

I tried

\begin{minipage}{\textwidth}
\begin{parcolumns}{2}
\colchunk{\begin{lstlisting}[caption=code 1,frame=tlrb]{Name}
void code()
{

}
\end{lstlisting}}

\colchunk{\begin{lstlisting}[caption=code 2,frame=tlrb]{Name}
void code()
{

}
\end{lstlisting}}

\colplacechunks
\end{parcolumns}
\end{minipage}

while the border of the listings end up in chunks as follows: chunked listing

Btw I'm using the texlive-package & pdflatex on Ubuntu and the document class is

\documentclass[
a4paper,
10pt,
twoside,
openright,
notitlepage,
parskip=half,
]{scrreprt}

Any idea is appreciated.

40

You can use two minipages:

\documentclass[
a4paper,
10pt,
twoside,
openright,
notitlepage,
parskip=half,
]{scrreprt}
\usepackage{listings}
\usepackage{parcolumns}
\begin{document}

\noindent\begin{minipage}{.45\textwidth}
\begin{lstlisting}[caption=code 1,frame=tlrb]{Name}
void code()
{

}
\end{lstlisting}
\end{minipage}\hfill
\begin{minipage}{.45\textwidth}
\begin{lstlisting}[caption=code 2,frame=tlrb]{Name}
void code()
{

}
\end{lstlisting}
\end{minipage}

\end{document}

enter image description here

  • A+1: great. exactly what i was looking for. thanks a lot! – Atmocreations Nov 17 '11 at 14:04
  • 2
    As described here, listings has an option for spreading a listing over two columns. It is not exactly what the OP asks for, but noted here for posterity. – Ioannis Filippidis Feb 2 '15 at 8:01
  • 1
    Use \begin{lstlisting}[t] if you want the two lstlisting's not to be vertically centered if they are of uneven length. – Chinni Dec 1 '16 at 22:22
  • 2
    If you need lstlistings to be centered top, then you need to use \begin{minipage}[t] – immanis Mar 20 '18 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.