带有kableExtra的html文档rmarkdown中的紧凑表? [英] Compact table in html document rmarkdown with kableExtra?
问题描述
我正在尝试制作紧凑" RMarkdown中的表格
I'm trying to make a 'compact' table in an RMarkdown
我已经尝试了一些方法,主要是设置自定义CSS类和
I've tried a few things, mostly variations on setting a custom css class and providing the custom css class to a code chunk
我尝试了很多变体,所有这些变体我都可以看到源代码的流向(通过编织html文档,在chrome中打开以及 cmd + opt + u 查看源并检查源)
I've tried a lot of variations, all of which I can see flow through to the source code (accessed via knitting the html document, opening in chrome, and cmd + opt + u to view source and inspecting the source)
但是,我无法弄清楚在kableExtra
表中简单地使行变薄(我认为这只是减少单元格填充)的必要条件
However, I can't work out what's necessary to simply make rows thinner (I believe that's simply reducing cell padding) in a kableExtra
table
这是我尝试过的一种变体,但是这些行并没有像希望的那样紧凑(它们是标准高度)
Here's one variation of what I've tried, but the rows are not compact as hoped (they are the standard height)
完成了以下操作:
---
output: html_document
---
```{r setup, include=FALSE}
library(dplyr); library(kableExtra)
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(dplyr)
library(kableExtra)
```
<style>
pre code, pre, code {
padding: 200 !important;
}
</style>
```{r}
iris %>%
kable %>%
kable_styling("striped", full_width = F) %>%
column_spec(4:5, bold = T) %>%
row_spec(3:5, bold = T, color = "white", background = "#D7261E")
```
但是请注意,自定义css并没有生效
but note that the custom css is not taking effect
推荐答案
最简单的方法是覆盖Bootstrap CSS,减小padding
属性的值(默认值为8px
):
The easiest way is to override the Bootstrap CSS, decreasing value of padding
property (default value is 8px
):
<style>
.table>tbody>tr>td{
padding: 1px;
}
</style>
正如您所指出的那样,检查源将使您获得上面的值:
As you pointed out, inspecting the source will lead you to the values above:
这篇关于带有kableExtra的html文档rmarkdown中的紧凑表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!