views:

397

answers:

2

Hello *,

I currently have a problem, that listings package cannot spread source files across multiple pages. In the doc is written, that the "framed" package should be used for various formatting option. Unfortunately I did not find any docs for the "framed" package. My current source formatting looks like this for C# sources:

Source Formatting

My formatting for "listings" package is:

\newcommand{\sourceFormatterCSharp}
{
\lstset
{ language=[Sharp]C
, captionpos=b
%, frame=lines
, morekeywords={var,get,set}
, basicstyle=\footnotesize\ttfamily
, keywordstyle=\color{blue}
, commentstyle=\color{darkgreen}
, stringstyle=\color{darkred}
, backgroundcolor=\color{lightgrey}
, numbers=left
, numberstyle=\scriptsize
, stepnumber=2
, numbersep=5pt
, breaklines=true
, tabsize=2
, showstringspaces=false
, emph={double,bool,int,unsigned,char,true,false,void,get,set}
, emphstyle=\color{blue}
, emph={Assert,Test}
, emphstyle=\color{red}
, emph={[2]\#using,\#define,\#ifdef,\#endif}
, emphstyle={[2]\color{blue}}
, frame=shadowbox
, rulesepcolor=\color{grey}
, lineskip={-1.5pt} % single line spacing
}
}

% first optional param is placement
% param1 file name without extension
% param2 chapter number, e.g. 1 or 2 ...
% param3 caption to use
\newcommand{\embedCSharp}[4][htbp]
{
\sourceFormatterCSharp
\includeListing{#1}{#4}{#3:#2}{#3/#2.cs}
}

Can anybody help me achieving similar looking results using "framed" package or any other for my source to look like this but be distributable across pages? An example how to embed a listing in the frame would not satisfy, since I was so far myself.

Many thanks,
Ovanes

+1  A: 

The framed documentation is within the .sty file itself. Just use it like this:

\documentclass{article}
\usepackage{framed,lipsum}
\begin{document}
\begin{framed}
\lipsum[1-10]
\end{framed}
\end{document}

From the docs, you can also use:

  • framed -- ordinary frame box (\fbox) with edge at margin
  • shaded -- shaded background (\colorbox) bleeding into margin
  • snugshade -- similar
  • leftbar -- thick vertical line in left margin

Putting your listings instead of lipsum in the example above will allow multiple pages of code with a frame around it all; you won't be able to get identical output to listings, but should be able to tweak things to get things looking okay.

Will Robertson
Thanks for the answer, but I would like to get identical listings. Another point is, where will the caption appear. After I tried it I had line numbers appear on the border.
ovanes
+1  A: 

The listings package already supports splitting code across pages; see example below (sorry about the long listing). Note that you cannot have a float that breaks across pages, so you'll need to use the caption package (for example) to insert a caption at the beginning of the lstlisting environment.

\documentclass{article}
\usepackage[a5paper,landscape]{geometry}
\usepackage{xcolor,listings}
\begin{document}
\definecolor{lightgrey}{gray}{0.8}
\lstset
{
captionpos=b
, backgroundcolor=\color{lightgrey}
, numbers=left
, numberstyle=\scriptsize
, stepnumber=2
, numbersep=5pt
, frame=shadowbox
, rulesepcolor=\color{gray}
}
\begin{lstlisting}
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
\end{lstlisting}
\end{document}
Will Robertson
The problem here is that all my captions are at the bottom. This is the style of the document. I can't just introduce the caption upon the source listing, but use anywhere else captions beneath. Sometimes I have captions, which are 2 lines long that looks pretty strange, having 2 lines long captions at the top of listing. It would be fine to have a package like "framed" which produces no border and margins at all. I know that I will have no closing line in the listing which is split across pages, but I can live with that.
ovanes
It is standard to have captions at the beginning of multi-page tables. It would be fine to do so here as well, in my opinion. I don't know what you mean about using the framed package, because listings already will break over pages so I don't see how it could improve things.
Will Robertson
Yes you are right. I tested it, it works. Would be cool if I could set some margin for the break, so that text does not immediately starts after the break, look a bit strange. But anyway many thanks for your help!
ovanes