I am new to knitr and in the past I had some basic knowledge of latex, so I googled already hoping to find a solution that has already been posted somewhere. However, I could not solve my problem. I hope someone is kind enough to help.
I have a data frame of 14 columns and many rows, say 60. Using the data, I need to create a PDF report in the landscape layout and present this data frame as a table.
The closest solution I found is here
tex.stackexchange.com: LaTex Longtable spans several pages
I used some hints. However, the table is not set up properly. The far right column (s) are clipped to the right edge of the page. There is no “Continue” at the end of the page at the end of the table. I post my code and picture here.
After deciding to correctly place long tables on the page, if I am missing anything obvious, please do not shoot :) I'm 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{}
\renewcommand{\headrulewidth}{0.5pt}
\setlength\headheight{40mm}
\begin{document}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{
\renewcommand*{\arraystretch}{1.0}
%
\section{My Long Table}
%\begin{center}
%\begin{small}
%\setlongtables
%\begin{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 = "!htp"
, caption.placement = "top"
, include.rownames = TRUE
, include.colnames = TRUE
, size = "footnotesize"
, tabular.environment = 'longtable'
, floating = FALSE
, add.to.row = list(pos = list(0),command =
paste("\\hline \\endfirsthead" ,
"\\caption[]{My Caption should be here} \\label{tab:The Table} \\\\ \\hline",
paste("&", names(df), collapse=" "),
"\\\\ \\hline ",
"\\endhead",
"\\hline \\multicolumn{11}{r}{\\textit{Continued}} \\
\\endfoot
\\endlastfoot",collapse=" ")))
@
%\end{longtable}
%\end{small}
%\end{center}
\end{document}
