I am using this code chunk
```{r, echo = FALSE}
knitr::kable(df)
```
However I would like to reduce the size of all font inside this table so that the output looks nicer. Is there a way to do that with kable or is there another package which supports it?
You can also try library(kableExtra)
. It has a lot of options to customise the table.
Specifically, for font size: https://haozhu233.github.io/kableExtra/awesome_table_in_html.html#font_size
df %>%
kable("html") %>%
kable_styling(font_size = 7)
我用\\微小后的功能和\\ normalsize,它适用于使用格式乳胶 降价 .pdf和之前。
When you are happy with a global setting, use css on .table
. To set it for one table, the only method I am aware of uses a div
. Both methods cannot be used for latex etc, but the global method looks cleaner to me, because formating is delegated to a separate css.
---
title: "Small kable"
output:
html_document:
css: kable.css
---
# Global setting
```{r}
library(knitr)
kable(iris[1:5,])
```
# Local setting, not portable
<div class="verysmall">
```{r}
kable(iris[1:5,])
```
</div>
CSS File
.table{
width:auto;
font-size: 12px;
}
.verysmall .table{
font-size: 8px;
}
I also use auto-formatting for kable-tables in most cases.
Dieter's answer worked for me. My first time using CSS in rmarkdown. Instead of using a separate CSS file, I embedded the following code towards the top of my rmarkdown doc, as referenced here: https://bookdown.org/yihui/rmarkdown-cookbook/html-css.html .
```{css, echo = FALSE}
.verysmall .table{
font-size: 8px;
}
```
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.