I am new to knitr and I have had some very basic latex knowledge in the past, so I googled already hoping to find a solution that was already posted somewhere. However, I was not able to solve my problem. I am hoping someone will be kind enough to provide help.
I have a data frame of 14 columns and many rows, let's say 60. Using the data I need to produce a PDF report in landscape layout and present this data frame as a table there.
The closest solution I found is here at
tex.stackexchange.com: LaTex Longtable spanning several pages
I used some of the hints there. However, the table is not placed properly. The rightmost column(s) are cut-off at the right edge of the page. The table does not have "Continued" word at the end of the page. I am posting my code and the picture here.
I am after a solution to place the longtables properly on the page, if I am missing anything obvious please do not shoot :) I am really new to this.
documentclass[a4paper, landscape]{article}
usepackage[a4paper, margin=1in, hmarginratio=1:1, landscape]{geometry}
usepackage{longtable}
usepackage{graphicx}
usepackage{xcolor}
definecolor{myblue}{RGB}{24,57,121}
usepackage{lipsum}
usepackage{booktabs}
usepackage{colortbl}
usepackage{array}
usepackage{rotating}
usepackage{fancyhdr}
pagestyle{fancy}
fancyhead{}
fancyfoot{}
enewcommand{headrulewidth}{0.5pt}
setlengthheadheight{40mm}
egin{document}
ewcolumntype{L}[1]{>{
aggedrightarraybackslash}p{#1}}
ewcolumntype{C}[1]{>{centeringarraybackslash}p{#1}}
ewcolumntype{R}[1]{>{
aggedleftarraybackslash}p{#1}}
enewcommand*{arraystretch}{1.0}
%
section{My Long Table}
%egin{center}
%egin{small}
%setlongtables
%egin{longtable}
<<echo=FALSE, eval=TRUE, results='asis'>>=
library(knitr)
library(xtable)
df <- data.frame(replicate(13, sample(1000000:9000000, 60,replace=TRUE)))
df$Sum <- rowSums(df)
totals <- colSums(df)
df <- rbind(df, totals)
names(df) <- c("Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014", "May 2014", "Jun 2014", "Jul 2014",
"Aug 2014", "Sep 2014", "Oct 2014", "Nov 2014", "Dec 2014", "Jan 2015", "Sum")
#
dtable <- xtable( x = df)
print ( dtable
#, table.placement = "H"
, table.placement = "!htp"
, caption.placement = "top"
, include.rownames = TRUE
, include.colnames = TRUE
, size = "footnotesize"
, tabular.environment = 'longtable'
, floating = FALSE
#, scalebox = 0.7
#, width = 0.8
, add.to.row = list(pos = list(0),command =
paste("\hline \endfirsthead" , # First caption
"\caption[]{My Caption should be here} \label{tab:The Table} \\ \hline", # Additional captions
paste("&", names(df), collapse=" "),
"\\ \hline ",
"\endhead",
"\hline \multicolumn{11}{r}{\textit{Continued}} \
\endfoot
\endlastfoot",collapse=" ")))
@
%end{longtable}
%end{small}
%end{center}
end{document}
See Question&Answers more detail:
os