I'm using the following code in .Rnw
file to generate a longtable
<<label = tabggplot2df, echo = FALSE, results = tex >>=
print(
xtable(
x = ggplot2df
, caption = "Functions in ggplot2"
, label = "tab:ggplot2df"
, align = "r|l|l"
)
, table.placement = "H"
, caption.placement = "top"
, include.rownames = TRUE
, include.colnames = TRUE
, size = "footnotesize"
, hline.after = c(-1, nrow(ggplot2df))
, tabular.environment="longtable"
, floating=FALSE
, add.to.row = list(pos = list(0), command = "\\hline \\endhead ")
)
@
I want to put something like this Table 1.1 (Continued …) Caption after the first page an bottom line at each page. My code is generating an extra bottom line for the last page and one extra vertical line. I'd highly appreciate if you help me to figure out these issues. Thanks
Best Answer
How to put a "continued on next page" at the page bottom of a longtable is described in the documentation of longtable. Instead of telling you to read the manual, I will show you my code, which solves these issues:
The
xtable
documentation in R describes the digits, display and align commands. These are invaluable when you try to make more complex tables, for example they are very useful in combination withsiunitx
table formats.When I need to
print()
the xtable, the following works pretty well, and also removes that pesky extra bottomrule (note that I use the booktabs package (which uses\toprule
,\midrule
and\bottomrule
instead of\hline
, but you just replace those rule commands with hline if you don't fancy booktabs).These code snippets contain all you need to solve your issues (plus some). I hope it's not too overwhelming. As you may notice, the
longtable.header
string is quite complicated, mainly because I needed to incorporate the nicer-looking horizontal rules of booktabs.longtable.header
can be significantly simplified if\hline
is used instead, although\hline
looks awful in comparison to proper rules, in my opinion.