I'm a newbie here, and on \Latex too.
I'm inserting some Tcl code into my PhD thesis using the superb listings package.
I'm using book class, twoside as default.
Also, using geometry package, controlling the margins (I have a marginpar defined also).
The problem is that I want the source code (lines with 80 characters) to be printed in the
body + margins, such that I do not need to use a small font (I'm trying to avoid line
breakings). I was not successfull. Because the listings package always extends the listing to
the right, and thus, on even pages the listings goes out the body page.
By default, the base line width for listings is \linewidth. I tryed to change this to:
\textwidth + \marginparwidth + \marginparsep but, the listings package is not able to deal with the odd and
even pages correctly. It always extends the "listing" to the same side (right) (outer on odd
pages, and inner on even pages).
I tryed to play with the conditional "ifthen" package, to control variables xleftmargin and
xrightmargin, but Latex complains about it. On the other hand, I was successful changing the
background color in this way.
Also played a little bit with putting the listings environment inside a minipage, but minipages
do not cross pages. Listings can

Here is a minimal example of what I'm doing:
Code: Select all
\documentclass[11pt,pdftex]{book}
\usepackage[a4paper,twoside,inner=3cm,outer=6.15cm,marginparwidth=2cm,%
marginparsep=10pt,includeheadfoot]{geometry}
\usepackage{listings}
\usepackage{calc}
\usepackage{color}
%preamble
\newlength{\lstlength}
\setlength{\lstlength}{\textwidth + \marginparwidth + \marginparsep}
\begin{document}
\lstset{linewidth=\lstlength,numbers=left, numbersep=10pt,%
%backgroundcolor=\ifthenelse{\isodd{\thepage}}{\color{gray}}{\color{yellow}}%
backgroundcolor=\color{yellow}
}
\lstinputlisting[firstnumber=3,linerange=3-100]{some.file}
\end{document}
Cheers,
Nuno
P.S. Sorry if it was too confusing