# How to avoid that listings are interrupted by floats?

And again I have another problem I just can't figure out. I defined a listing with some XML code:

\begin{lstlisting}[captionpos=b, caption=XML detection strategy for Refused Parent Bequest, label=lst:refused_parent_bequest]
<strategy name="Refused Parent Bequest" ...>
<gate type="AND">
<gate type="OR">
<gate type="AND">
<rule>
<metric>NProtM</metric>
<comparison>greater than</comparison>
<value>10</value>
</rule>
<rule>
<metric>BUR</metric>
<comparison>smaller than</comparison>
<value>0.33</value>
</rule>
</gate>
<rule>
<metric>BOvR</metric>
<comparison>smaller than</comparison>
<value>0.33</value>
</rule>
</gate>
<gate type="AND">
<gate type="OR">
<rule>
<metric>AMW</metric>
<comparison>greater than</comparison>
<value>-1</value>
</rule>
<rule>
<metric>WMC</metric>
<comparison>greater than</comparison>
<value>-1</value>
</rule>
</gate>
<rule>
<metric>NOM</metric>
<comparison>greater than</comparison>
<value>-1</value>
</rule>
</gate>
</gate>
</strategy>
\end{lstlisting}


Very near to this I also defined a table. Now the problem is the listing starts on the first page, the there is a page break, then there is the table and then the listing continues. How can I force the layout to not interrupt my listing?

-
–  Martin Scharrer Sep 18 '11 at 22:59

You can adjust the placing of floats the following ways:

For once you could add \FloatBarrier from the placeins package before the listing to flush all previous floats. This wont help if the table is defined just after it.

The \suppressfloats macro allows you to suppress floats on the current page. You could add it before the listing inside an \afterpage{...} (afterpage package) so that it counts for the second page of the listing.

There is also the flafter package which makes floats only appear after their definition. This should handle a table defined shortly after the listing.

-
Another (and less hacky) possibility is, to add the float Parameter to your listing. It will then float like the tables do, but floating environments don't interrupt each other:
\begin{lstlisting}[float]