【问题标题】:Group only some columns in LaTeX table using R使用 R 仅对 LaTeX 表中的某些列进行分组
【发布时间】:2018-02-12 22:36:45
【问题描述】:

我正在尝试在 RMarkdown 中创建一个类似于以下示例的表:

---
title: "Example"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```


```{r cars, echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(Hmisc)
latex(mtcars, file = "", cgroup = c("mpg", "cyl"), n.cgroup = c(1,10))
```

我想将第 2 列到第 10 列分组。关于如何使用 Hmisc 包或任何其他 R 包完成此任务的任何想法?

【问题讨论】:

    标签: r latex hmisc


    【解决方案1】:

    我认为仅在第一列使用空白标题名称即可满足您的需求:

    latex(mtcars, file = "", cgroup = c("", "cyl"), n.cgroup = c(1,10))
    

    结果:

    【讨论】:

    • 太棒了!是否可以将行名(mtcars)与底部对齐(类似于mpg)?
    【解决方案2】:

    使用我的包:

    library(huxtable)
    hux_cars <- as_hux(mtcars, add_colnames = TRUE)
    hux_cars <- insert_row(hux_cars, c('mtcars', 'cyl', rep('', 9)))
    colspan(hux_cars)[1, 2] <- 10
    align(hux_cars)[1, 2] <- 'centre'
    bold(hux_cars)[1, ] <- TRUE
    position(hux_cars) <- 'left'
    quick_pdf(hux_cars)
    

    产生:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多