[Tex/LaTex] Changing side of line numbering in two columns documents

line-numberinglistingspositioningtwo-column

I'm trying to type some report and I have a small problem with the twocolums document class and the line numbering in listings.

The document is on two columns :

\documentclass[8pt,[...],a4paper,twocolumn]{article}

The listings can end up either on the left or the right column. The problem is: if I put

\lstset{numbers=left,frame=tb,[...]}

the space between the columns is not sufficient when the listing is on the right column and the text from the first column is written over.

Is there any way to ask the listings to put the line numbers "outside" ?

Best Answer

\documentclass[a4paper,twocolumn]{article}
\usepackage{listings}
\lstset{numbers=left,frame=tb,numbersep=1em,xleftmargin=2em,
  basicstyle=\ttfamily\small}
\parindent=0pt

\begin{document}

\rule{\linewidth}{1pt}
\begin{lstlisting}
 \def\showDiff#1#2{}%
\end{lstlisting}

\newpage

\rule{\linewidth}{1pt}
\begin{lstlisting}
 \def\showDiff#1#2{}%
\end{lstlisting}

\end{document}
Related Question