标题包装在RStudio的降价

时间:2018-01-11 12:17:14

标签: r r-markdown

我想拆分表的列标题。我已经查看了这个说明https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html,但我没有找到问题的答案。我试过使用column_spec但是没有用。另外,我想通过颜色突出显示列标题。

下面是一个例子:

---
title: "Report"
output: html_document
---

```{r}
library(knitr)
library(kableExtra)
```

```{r}
options(knitr.table.format = "html") 
```

```{r}
text_tbl <- data.frame(
  Items = c("Item 1", "Item 2", "Item 3"),
  Features = c(
"Description 1",
"Description 2",
"Description 3"
)
)
names(text_tbl)[2]="Column name to break"
kable(text_tbl, "html") %>%
  kable_styling(full_width = F) %>%
  column_spec(1, bold = T, border_right = T) %>%
  column_spec(2, width = "30em")
```

谢谢大家

1 个答案:

答案 0 :(得分:1)

尝试稍微减小第2列的宽度,并对标题行使用row_spec(0,...)。

kable(text_tbl, "html") %>%
 kable_styling(full_width = F) %>%
 column_spec(1, bold = T, border_right = T) %>%
 column_spec(2, width = "8em") %>%
 row_spec(0, color = "red")