Curious float layout from listings package
- From: Chris Newton <please.reply@xxxxxxxx>
- Date: Tue, 09 May 2006 01:46:23 +0100
Hi all,
I've encountered an annoying layout oddity while using the listings package with floating listings, and none of my tweaking so far seems to fix it. I'd be grateful if anyone can suggest anything else to try...
In essence, I have created a new environment for floating listings, thus:
\lstdefinestyle{floatbox}{
basicstyle=\ttfamily\footnotesize,
float=ptbh,
frame=topline}
\lstnewenvironment{myfloat}[2]{\lstset{style=floatbox,label=#1,caption=#2}}{}
In one part of my document, I have (fairly close together) several short listings:
== Start of code ==================================================
I have some text in a paragraph, referring to listing~\ref{listing:first}.
\begin{myfloat}{listing:first}{My first listing}
About half
A dozen
Lines go here
\end{myfloat}
And then I have some more text, which is equally exciting, referring to listing~\ref{listing:second}.
\begin{myfloat}{listing:second}{My second listing}
Another half a dozen
Lines or so
Go here
\end{myfloat}
And then, unsurprisingly, there's some more text, filling out the remainder of a paragraph to illustrate the problem. It would be nice if all of this text stayed together.
== End of code ====================================================
Unfortunately, these render something like the following:
== Start of output ================================================
I have some text in a paragraph, referring to listing 1. And then I have some more text, which is equally exciting, referring to listing 2.
(Page break)
Listing 1: My first listing
---------------------------
About half
A dozen
Lines go here
And then, unsurprisingly, there's some more text, filling out
Listing 2: My second listing
----------------------------
Another half a dozen
Lines or so
Go here
the remainder of the paragraph to illustrate the problem. It would be nice if all of this text stayed together.
== End of output ==================================================
That is, a single line of the body text is unattractively stranded between two fairly short listings at the top of the second page, complete with spacing either side. I get a similar effect in another place in my document when the line in between the two listings contains the reference to and definition of the second listing.
The only explanation I can think of is that the first listing is being placed (t)op in each case, while the second listing is being placed (h)ere, and the latter happens to work out just below the former. However, it would be nice to avoid the unsightly single-line effect. Can anyone think of a way to do this, short of manually going through the document and replacing the predefined environment with a custom one lacking the (h)ere option every time this occurs? (The environment generally gives me good results, so I'm somewhat reluctant to remove the (h)ere option globally.)
And insights or suggestions would be much appreciated.
Thanks,
Chris
.
- Prev by Date: Re: how to nest enumerate without change of line?
- Next by Date: Re: hat accent character?
- Previous by thread: clash between pst-pdf.sty and classicthesis.sty; pplr9o+20 error
- Next by thread: Including Word documents in Appendix
- Index(es):
Relevant Pages
|