【发布时间】:2014-09-02 17:25:21
【问题描述】:
我需要在 RMarkdown 的 Tufte_handout 中旋转列名,我认为“\usepackage{rotating}”丢失了。但是无论我怎么尝试,我都无法在没有错误的情况下将其输入。
这是一个工作示例(RStudio 中模板的简化版本)。绘制了前两个表(没有旋转的列名),但是当在最后两个使用旋转的列名的表中删除“#”时,它会失败。
---
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)
```
更新:感谢@Jonathan 的耐心支持,我终于成功了。这些是步骤:
在 RStudio 中创建了新项目:enhancedtufte(作为一个包)
在enhancedtufte下创建了目录inst
在inst下创建目录rmarkdown
在 rmarkdown 下创建目录模板
运行命令 "system.file("rmarkdown/templates/tufte_handout", package="rmarkdown")" 以查找原始 tufte_handout 的位置,并将目录 "tufte_handout"(从模板下)复制到模板 -上一步创建的目录
将 template.yaml 中的行从“名称:Tufte Handout”修改为“名称:Tufte Handout 2”
在 RStudio 中单击“构建和重新加载”
选定文件 -> 新文件 -> R Markdown...,然后从模板 -> Tufte Handout 2 {enhancedtufte}
在新文档中,将“输出:rmarkdown::tufte_handout”行更改为“输出:enhanced_tufte::tufte_handout”
将所有文件从https://github.com/rstudio/rmarkdown/tree/master/R复制到enhancedtufte/R
Edited package name to "enhancedtufte in tufte_handout.R"# 获取 tufte handlout 模板 模板
在 tufte-handout.tex 中添加了“\usepackage{rotating}”
构建和重新加载
- Knit 适用于侧向桌子(删除上面示例中的 #)
【问题讨论】:
标签: r knitr r-markdown xtable