R Markdown文档中kable输出(带有booktabs选项)中的每五行之后的空格 [英] Space after every five rows in kable output (with booktabs option) in R Markdown document

查看:140
本文介绍了R Markdown文档中kable输出(带有booktabs选项)中的每五行之后的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用knitr::kable()将表呈现为 R Markdown 文档的一部分(该文档本身是 bookdown 项目的一部分).特别是,booktabs选项(通过将booktabs参数设置为等于TRUE)以一种美观的方式呈现该表.但是,我希望每五行后面不要有空格.

I am using knitr::kable() to render tables as part of an R Markdown document (that itself is part of a bookdown project). In particular, the booktabs option (through setting the booktabs argument to equal TRUE) renders the table in a nice-looking way. However, I'd like for there not to be a space after every five rows.

例如,这里是代码以及以PDF呈现时书本演示中的表格的显示方式:

Here, for example, is the code and how the table in the bookdown demo appears when rendered as a PDF:

knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE
)

我希望每五行之后出现的空间不包括在内,但是我似乎找不到在knitr::kable()中执行此操作的设置.

I'd like for the space that aappears after every five rows to not be included, but I cannot seem to find a setting in knitr::kable() that does this.

推荐答案

行高并不总是相等的原因是,默认情况下,当将booktabs指定为TRUE时,kable每5行插入一个\addlinespace显示在此处:

The reason why the row height is not always equal is that by default, kable inserts a \addlinespace every 5 rows when booktabs is specified as TRUE, as is shown here:

linesep = if (booktabs) c('', '', '', '', '\\addlinespace') else '\\hline'

要更改此设置,请在kable()上添加linesep = ""作为参数.

To alter this, add linesep = "" as an argument to kable().

knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE,
  linesep = ""
)

有关更多详细信息,请参见摆脱kable中的\ addlinespace .

也值得一提的是,如果您想更改样式,可以使用此选项.例如,linesep = c("", "", "", "\\hline")会每四个空格添加一条水平线.

It is also worth saying that you can play around with this option if you want to change the style. For example linesep = c("", "", "", "\\hline") would add a horizontal line every four spaces.

这篇关于R Markdown文档中kable输出(带有booktabs选项)中的每五行之后的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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