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

\floatname{rcode}{Code Example}

<<label = Example1, echo= true>>=
 bunch of R code
\caption{First code example}

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.

  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Jun 22, 2012 at 17:07
  • Your specifiers of the float parameters are wrong. Please see: tex.stackexchange.com/questions/39017/… Jun 22, 2012 at 17:15
  • You can try the knitr package instead of Sweave, with which you can use your own environment easily (e.g. gist.github.com/2760395) without writing \begin{rcode} and \end{rcode} repeatedly.
    – Yihui Xie
    Jun 22, 2012 at 20:14

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .