I need to rotate the column names in a Tufte_handout in RMarkdown, and I think "\usepackage{rotating}" is missing. But no matter how I try, I can't get it in without errors.
Here is a working example (reduced version of template in RStudio). The two first tables are plotted (without rotated colnames), but when "#" is removed in the last two tables with rotated colnames, it fails.
---
title: "Tufte Handout with rotated tables"
output: rmarkdown::tufte_handout
---
# Table from RStudio template
```{r, results='asis'}
library(xtable)
options(xtable.comment = FALSE)
options(xtable.booktabs = TRUE)
xtable(head(mtcars[,1:6]), caption = "Ok. Template from RStudio.")
```
# Modified table (working)
```{r, results='asis'}
library(xtable)
options(xtable.comment = FALSE)
options(xtable.booktabs = TRUE)
the.table <- xtable(head(mtcars[,1:6]), caption = "Also ok.")
print((the.table), rotate.colnames=FALSE)
```
# Modified table (not working)
```{r, results='asis'}
library(xtable)
options(xtable.comment = FALSE)
options(xtable.booktabs = TRUE)
options(xtable.rotate.colnames = TRUE)
# Next row will fail
#xtable(head(mtcars[,1:6]), caption = "Not ok.")
```
# Modified table (not working)
```{r, results='asis'}
library(xtable)
options(xtable.comment = FALSE)
options(xtable.booktabs = TRUE)
the.table <- xtable(head(mtcars[,1:6]), caption = "Not ok.")
# Next row will fail.
#print((the.table), rotate.colnames=TRUE)
```
Update: Thanks to @Jonathan's patient support, I finally got it working. These are the steps:
Created new project in RStudio: enhancedtufte (as a package)
Created diretory inst under enhancedtufte
Created directory rmarkdown under inst
Created directory templates under rmarkdown
Ran command "system.file("rmarkdown/templates/tufte_handout", package="rmarkdown")" to find where original tufte_handout is, and copied directory "tufte_handout" (from under templates) to the templates-directory created in previous step
Edited line in template.yaml from "name: Tufte Handout" to "name: Tufte Handout 2"
Clicked "Build & Reload" in RStudio
Selected File -> New File -> R Markdown..., and then From Template -> Tufte Handout 2 {enhancedtufte}
In new document, changed line "output: rmarkdown::tufte_handout" to "output:enhanced_tufte::tufte_handout"
Copied all files from https://github.com/rstudio/rmarkdown/tree/master/R to enhancedtufte/R
Edited package name to "enhancedtufte in tufte_handout.R "# get the tufte handlout template template <- system.file( "rmarkdown/templates/tufte_handout/resources/tufte-handout.tex", package = "enhancedtufte" )"
Added "\usepackage{rotating}" in tufte-handout.tex
Build & Reload
The \usepackage
directive needs to go into the TeX template that Pandoc uses.
Unfortunately it's not extremely easy to change the template, but it's not impossible. Here's what you need to do:
system.file("rmarkdown/templates/tufte_handout", package="rmarkdown")
; you'll want to copy this folder to your package's inst/rmarkdown
folder. tufte-handout.tex
to include \usepackage{rotating}
; build and load your package.output: enhanced_tufte::tufte_handout
. You can also just modify RMarkdown's template directly to include \usepackage{rotating}
, but of course that'll get reverted the next time you install the rmarkdown package.