Question

I'm using Sweave and latex() from the Hmisc package to insert a longtable in my PDF.

When I do it the first time, the table is spread nicely, filling up the pages with the table.

If I do it again, some pages are only half full (like page 4 of PDF), which looks weird and somehow wrong because it seems to be unnecessary space.

Is there a way to control this? Or what could I do to improve the look? Especially, if I'm adding some text and graphs, it won't look good with the empty space on page 4.

\documentclass{article}

\usepackage{Sweave}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}
\SweaveOpts{concordance=TRUE}

I want to insert this longtable
<<tab.R,echo=FALSE,results=tex>>=
library(Hmisc)
#library(xtable)
x <- matrix(rnorm(1000), ncol = 10)
x.big <- data.frame(x)
latex(x.big,"",file="",longtable=TRUE, dec=2,caption='First longtable spanning several pages')
@

then write some text. Maybe add a graph...

And then another table
<<tab.R,echo=FALSE,results=tex>>=
latex(x.big,"",file="",longtable=TRUE, dec=2,caption='Second longtable spanning wrongly')
@

\end{document}
Was it helpful?

Solution

Don't pass this question over to the latex group, this is a problem of Hmisc/latex that adds a \clearpage into tex every 40 lines by default. Check parameter lines.page=40 of latex. I do not understand why this default has been set, but something like

latex(x.big,"",file="",longtable=TRUE, dec=2,
  caption='Second longtable spanning wrongly', lines.page=4000)

gets you around the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top