knitr::kable is there a way to reduce the font size?

淺唱寂寞╮ 提交于 2019-12-05 03:29:31

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)

I use \tiny before the function and \normalsize after it, which works for .pdf using the formats latex and markdown.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!