As mentioned in baptiste, if you insert R commands in LaTeX, pandoc will not parse them and place them as they were in the generated LaTeX: this causes an error. In addition to the Baptist with a good and simple fix, you can use the xtable R package, which offers the possibility of creating more sexier LaTeX tables from the output of R. For the following example, you need to add \usepackage{rotating} to the header.tex file:
--- title: "Mixing portrait and landscape" output: pdf_document: keep_tex: true includes: in_header: header.tex --- ```{r, echo=FALSE} library(xtable) ``` Portrait ```{r, results='asis', echo=FALSE} print(xtable(summary(cars), caption="Landscape table"), comment=FALSE) ``` Landscape: ```{r, results='asis', echo=FALSE} print(xtable(summary(cars), caption="Landscape table"), floating.environment="sidewaystable", comment=FALSE) ```
The second table will be printed in a sidewaystable environment, and not in a regular table : therefore, it will be printed in landscape mode on a separate page. Please note that tables and figures placed in landscape mode with the lscape package or in the sideways environment will always be placed on a separate page, see page 91 of this very important document:
http://www.tex.ac.uk/tex-archive/info/epslatex/english/epslatex.pdf
Since I find this a bit annoying, I managed to find a way to save both portrait and landscape tables on one page (losing all day in the process):
--- title: "Mixing portrait and landscape" output: pdf_document: keep_tex: true includes: in_header: header.tex --- ```{r, echo=FALSE} library(xtable) ``` Portrait: ```{r, results='asis', echo=FALSE} print(xtable(summary(cars), caption="Portrait table."), comment=FALSE) ``` Landscape: ```{r, results='asis', echo=FALSE} cat(paste0( "\\begin{table}[ht]\\centering\\rotatebox{90}{", paste0(capture.output( print(xtable(summary(cars)), floating=FALSE, comment=FALSE)), collapse="\n"), "}\\caption{Landscape table.}\\end{table}")) ```
For the terrain table, I used the \rotatebox given here:
http://en.wikibooks.org/wiki/LaTeX/Rotations
To do this, I only need to create part of the tabular table with the print(xtable(... , then I have to capture the output and manually surround it with the table and rotatebox commands, converting everything to the output of the R string so that pandoc does not treat them as LaTeX environment For a clean rmarkdown solution ... good luck!