# Changing side of line numbering in two columns documents

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" ?

-

\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}

-
Could you explain what your code is doing? –  Seamus Jan 23 '11 at 12:18
It produce two listings, one on each column, with the numbers on the left. But instead of increasing the space between the columns, it adds a margin for the numbers, so the listing is not as large as before without having narrower columns. Not quite the solution i was thinking about, but it produces a good result. –  Thomas Schwery Jan 23 '11 at 17:24
Even though it doesn't exactly answer the question, it's the solution i'm using now ... –  Thomas Schwery Jan 29 '11 at 21:53

Even if it were possible, for code listings I would find line numbers on the right hand side unclear and confusing. I suggest to increase the space between columns in your document:

\setlength{\columnsep}{25pt}


EDIT: Fixed embarassing typo in code sampling.

-
That's what i'm doing for now, but i would like to know if there was a way to change automatically the side of the numbering depending on the column the listing is in. –  Thomas Schwery Jan 23 '11 at 13:00
the numbers are always on the left. See my example for setting it correct. –  Herbert Jan 23 '11 at 15:02

You can try this:

\documentclass[a4paper,twocolumn]{article}
\usepackage[switch]{lineno}

\begin{document}
\linenumbers

\end{document}

-
But that only gives you line numbering, one of many features of the listings package. –  Chris H Jan 30 '14 at 13:07