调整RMarkdown文档中用kable()制成的表格的宽度 [英] Adjusting width of tables made with kable() in RMarkdown documents

查看:930
本文介绍了调整RMarkdown文档中用kable()制成的表格的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在knitr中使用kable()函数制作表格时,是否可以调整列的宽度?

Is it possible to adjust the width of columns when making tables with the kable() function in knitr?

对于具有两列的表,像这样的块将生成一个表,该表占用了文档的整个宽度.我想使列更窄. 可以使用kable()完成此操作,还是需要其他软件包?

A chunk like this for a table with two columns produces a table that takes up the entire width of the document. I'd like to make the columns narrower. Can this be done with kable() or is another package needed?

此rmarkdown块

This rmarkdown chunk

```{r}
df <- data.frame(x = 1:10,
           y = 11:20)
library(knitr)
kable(df)
```

产生此表

kable(df, align = "l")左对齐会有所帮助,但我希望这两列彼此相邻.

Aligning left with kable(df, align = "l") helps a little but I'd like the two columns adjacent to each other.

推荐答案

您可以试用kableExtra软件包.

kable(x, "html") %>%
  kable_styling(full_width = F)

这篇关于调整RMarkdown文档中用kable()制成的表格的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆