title: Longtable in a knitr (PDF) document: using xtable (or kable)
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>The closest solution I found is here at
  <a href="https://tex.stackexchange.com/questions/220906/knitr-latex-longtable-spanning-several-pages-with-word-continued-at-bottom-and">tex.stackexchange.com: LaTex Longtable spanning several pages</a></p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <pre><code>\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]{&gt;{\raggedright\arraybackslash}p{#1}}
  \newcolumntype{C}[1]{&gt;{\centering\arraybackslash}p{#1}}
  \newcolumntype{R}[1]{&gt;{\raggedleft\arraybackslash}p{#1}}
  \renewcommand*{\arraystretch}{1.0}
  %
  \section{My Long Table}
  %\begin{center}
  %\begin{small}
  %\setlongtables
  %\begin{longtable}
  &lt;&lt;echo=FALSE, eval=TRUE, results='asis'&gt;&gt;=
  library(knitr)
  library(xtable)
  df &lt;- data.frame(replicate(13, sample(1000000:9000000, 60,replace=TRUE)))
  df$Sum &lt;- rowSums(df)
  totals &lt;- colSums(df)
  df &lt;- rbind(df, totals)
  names(df) &lt;- 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 &lt;- 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("&amp;", names(df), collapse=" "),
                    "\\\\ \\hline ",
                    "\\endhead", 
                    "\\hline \\multicolumn{11}{r}{\\textit{Continued}} \\                    
                    \\endfoot
                    \\endlastfoot",collapse=" ")))
  @
  %\end{longtable}
  %\end{small}
  
  %\end{center}
  \end{document}
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FV9XO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FV9XO.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/Ep8MN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ep8MN.png" alt="enter image description here"></a></p>