# Sweave Float environment over 2 pages

I have a bit of Sweave code as such:

<<label = Example1, echo= true>>=
//Bunch of R Code
@


I've tried putting it in my own float environment like so

\newfloat{rcode}{h!}{rcode}
\floatname{rcode}{Code Example}

\begin{rcode}[htb!]
<<label = Example1, echo= true>>=
bunch of R code
@
\caption{First code example}
\label{CodeEx1}
\end{rcode}


But then the float is too big and goes on the next page. How do I get it to split over the page like it did before the environment. I've tried the continuedfloat package and wasn't able to get it working. I've also tried the algorithm package and had problems there as well.

## 1 Answer

Floats deliberately stay together, and if necessary move to a later page to avoid leaving large spaces. Either accept this approach and use a \label/\ref to refer to your code, or don't put the code in a float and allow it to break over the page.