# 2 column: how to squeeze line numbering closer, shift code over in Lyx

I'm using 2-column in otherwise-default Lyx, with several program listings. Some of them have line numbers. Due to the 2-column layout, the line numbers take a good chunk of the gutter between columns. Is there a way to do any or all of the following?

• squeeze the line numbers a bit closer to the code listing
• move the code over a bit to the right (some left-margin setting for program-listing)
• allow the code to go a bit past the normal column width on the page side

Thanks!

• I don't usually modify spacing in this way so I won't be able to help, but you are more likely to get help if you post a minimal working example. Post the .lyx, the .tex, and the output you get. – scottkosty Nov 9 '13 at 4:47
• I'm not sure if you noticed, but I updated my answer below yesterday. I think it answers all three points in your question now. – Torbjørn T. Jan 8 '14 at 1:26

For your three points there are three parameters that can be modified to suit your needs. (See the listings manual for all options available.)

• xleftmargin -- left margin. By adjusting this you can move the listing left/right. (Negative values work.)
• xrightmargin -- right margin. By setting this to a negative value you allow the code to flow beyond the column width.
• numbersep -- defines the amount of whitespace between line number and code. Default is 10pt.

In LyX you apply these options in Document --> Settings --> Listings. Write each key=value pair separated by commas, e.g.

xleftmargin=1cm,xrightmargin=-1cm,numbersep=2pt


In the LaTeX code example below I also changed the font to a typewriter font, reduced the font size of the line numbers and enabled line breaking.)

\documentclass[twocolumn]{article}
\usepackage{listings}
\lstset{
xleftmargin=1em,      % <-- change this to a suitable length
xrightmargin=-0.5cm,  % <-- change this to a suitable negative length
numbersep=2pt,        % default 10pt
numbers=left,
numberstyle=\footnotesize,
basicstyle=\ttfamily,
breaklines=true}
\usepackage{lipsum} % for dummy text
\begin{document}
\lipsum[1]
\begin{lstlisting}
This
is
a
code
listing.
\end{lstlisting}
\lipsum[2-3]
\begin{lstlisting}
This
is
a very very very very very very very long
code
listing.
\end{lstlisting}
\lipsum[4-6]
\end{document}