首页 > 解决方案 > 如何删除 tint::tintHtml 在 kable 表中的单元格周围添加的白色填充/边框?

问题描述

我想摆脱每个细胞周围的白色。当我编织到 html_document 时,没有这样的填充。

我猜 tint.css 文件对此负责(https://github.com/eddelbuettel/tint/blob/master/inst/rmarkdown/templates/tintHtml/resources/tint.css

---
title: tintHtml() add padding to kable "
output:  tint::tintHtml
---
  
  
  
```{r}
library(kableExtra)
library(magrittr)
```


```{r}
knitr::kable(
  mtcars[1:6, 1:6], 
  caption = 'how do I get rid of white padding ?'
) %>%  
  row_spec(0, background = "blue", color = "white") %>% 
  row_spec(1, background = "green", color = "white") 

```

在此处输入图像描述

标签: r-markdownkabletint

解决方案


第一步:您可以“右键单击网页上的元素并选择检查元素

在此处输入图像描述

第二步:您需要覆盖默认的边框间距(Bootstrap CSS)属性:

border-spacing属性设置相邻单元格边界之间的距离。
注意:此属性仅在border-collapse独立时有效。

<style>
table{
  border-spacing: unset;    # values: inherent, initial, unset or 0px
}
</style>

输出:

---
title: tintHtml() add padding to kable "
output: tint::tintHtml
---
  
```{r}
library(kableExtra)
library(magrittr)
```
<style>
table{
  border-spacing: unset;    # inherent, initial, unset, 0px
}
</style>

```{r}
knitr::kable(
  mtcars[1:6, 1:6], 
  caption = 'how do I get rid of white padding ?'
) %>%  
  row_spec(0, background = "blue", color = "white") %>% 
  row_spec(1, background = "green", color = "white") 
```

在此处输入图像描述


推荐阅读