Reputation: 52498
I'm trying to make a 'compact' table in an RMarkdown
I've tried a few things, mostly variations on setting a custom css class and providing the custom css class to a code chunk
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)
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)
Which is done with:
---
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")
```
but note that the custom css is not taking effect
Upvotes: 0
Views: 1909
Reputation: 795
To make the kable rows smaller in a knit to HTML, you can use bootstrap_options = c("condensed") in your kable_styling:
kable_styling(bootstrap_options = c("condensed"))
See https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html
The pdf variant for it: https://cran.r-project.org/web/packages/kableExtra/kableExtra.pdf
Upvotes: 3
Reputation: 19
You could also do something similar within row_spec(1:nrow(iris), extra_css = "..")
Upvotes: 1
Reputation: 2821
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:
Upvotes: 4