减少用kable(,format ='markdown')创建的表中列之间的间距(Reduce spacing between columns in table created w

编程入门 行业动态 更新时间:2024-10-26 11:20:05
减少用kable(,format ='markdown')创建的表中列之间的间距(Reduce spacing between columns in table created with kable(, format = 'markdown'))

我尝试使用函数kable()的格式“markdown”创建一个表,但列之间的空格非常宽,表格在页面上延伸。 无论如何都要调整单元格大小,以便标记格式的表格不会延伸到页面上吗? 在乳胶格式中,它保留在页面内,但我不想要这种格式,也不想要html 。 我希望输出文件是.pdf。 我知道这里有一个类似的问题,但我的问题是格式降价的具体问题。 如果您认为这是重复,请合并问题。

可重复的例子:

--- title: "Example" author: "JAQuent" date: "7 Juni 2017" output: pdf_document --- \tiny ```{r results='asis', echo = FALSE, warning = FALSE} library(knitr) table1 <- data.frame(Factor1 = c('level 1', 'level 1', 'level 2', 'level 2'), Factor2 = c('level 1', 'level 2', 'level 1', 'level 2'), Parameter1 = sample(1000000:9999999, 2), Parameter2 = sample(1000000:9999999, 2), Parameter3 = sample(1000000:9999999, 2), Parameter4 = sample(1000000:9999999, 2), Parameter5 = sample(1000000:9999999, 2), Parameter6 = sample(1000000:9999999, 2), Parameter7 = sample(1000000:9999999, 2)) names(table1) <- c('Factor1', 'Factor2', 'Parameter1', 'Parameter2', 'Parameter3', 'Parameter4', 'Parameter5', 'Parameter6', 'Parameter7') kable(table1, format = 'markdown') kable(table1, format = 'latex') ```

I try to create a table using the format "markdown" of the function kable(), but the spaces between the columns are so wide that the table extends over the page. Is there anyway to adjust the cell size so that a table in markdown format does not extend over the page? In latex format it stays within the page, but I do not want this format nor do I want html. I want the output file to be .pdf. I know that a similar question has been asked here, but my question is specific to the format markdown. If you feel this is a duplicate, please merge the questions.

Reproducible example:

--- title: "Example" author: "JAQuent" date: "7 Juni 2017" output: pdf_document --- \tiny ```{r results='asis', echo = FALSE, warning = FALSE} library(knitr) table1 <- data.frame(Factor1 = c('level 1', 'level 1', 'level 2', 'level 2'), Factor2 = c('level 1', 'level 2', 'level 1', 'level 2'), Parameter1 = sample(1000000:9999999, 2), Parameter2 = sample(1000000:9999999, 2), Parameter3 = sample(1000000:9999999, 2), Parameter4 = sample(1000000:9999999, 2), Parameter5 = sample(1000000:9999999, 2), Parameter6 = sample(1000000:9999999, 2), Parameter7 = sample(1000000:9999999, 2)) names(table1) <- c('Factor1', 'Factor2', 'Parameter1', 'Parameter2', 'Parameter3', 'Parameter4', 'Parameter5', 'Parameter6', 'Parameter7') kable(table1, format = 'markdown') kable(table1, format = 'latex') ```

最满意答案

?kable中的几个示例包含填充参数。 0L让你更接近,但事实证明这个论点将采用负整数,所以

kable(table1, format = 'markdown', padding=-1L)

会产生更接近你所寻找的东西。

A couple of the examples in ?kable contain a padding argument. Feeding it 0L gets you closer, but it turns out that this argument will take negative integers, so

kable(table1, format = 'markdown', padding=-1L)

will produce something closer to what your are looking for.

更多推荐

本文发布于:2023-08-06 23:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间距   markdown   表中列   kable   format

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!