【问题标题】:How to add a caption to a resized table with scalebox in xtable?如何在 xtable 中使用 scalebox 为调整大小的表格添加标题?
【发布时间】:2017-12-04 22:11:27
【问题描述】:

我正在编写 R Markdown 文档。我有一个这样的数据框:

library(tidyverse)
library(xtable)

df <- tibble(a = 1:10, b = 1:10, c = 1:10, d = 1:10, e = 1:10, f =1:10,
g = 1:10, h = 1:10, i = 1:10)

我正在使用 xtable 包来创建显示表。由于表格太宽,我用 scalebox 参数缩放表格

xt <- xtable(df, caption = "Table 1")
print(xt, type = "latex", comment = FALSE,floating = F, 
include.rownames = F, scalebox = 0.50)

但是,标题不会显示在文档上。我能做什么?

【问题讨论】:

  • 谢谢。它通过添加参数table.placement = "!h" & floating = TRUE 起作用
  • 单独使用h 通常被认为是不好的做法(请参阅here)。如果你想严格控制浮动,你也可以选择table.placement = "H"
  • 谢谢。它也很有效。

标签: r r-markdown xtable


【解决方案1】:

如果您不限于使用xtable,我建议您切换到knitr::kablekableExtra

---
output: pdf_document
---

```{r setup, include=FALSE}
library(tidyverse)
library(knitr)
library(kableExtra)

df <- tibble(a = 1:10, b = 1:10, c = 1:10, d = 1:10, e = 1:10, f =1:10,
g = 1:10, h = 1:10, i = 1:10)
```

```{r table, results='asis'}
df %>%
  kable("latex", caption = "Table 1", booktabs = TRUE) %>%
  kable_styling(latex_options = c("striped", "hold_position"))
```

生产...

此外,latex_options 还可以使用等效的 scale_down 选项。但是,正如vignette 中所述,它将适合页面宽度,因此如果表格不够宽,也会按比例放大。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 2015-12-15
    • 2012-11-01
    相关资源
    最近更新 更多