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

查看:140
本文介绍了减少用kable(,format ='markdown')创建的表中各列之间的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用函数 kable()的"markdown"格式创建表,但是列之间的间隔太宽,以至于该表在页面上延伸.无论如何,是否有必要调整单元格的大小,以使markdown格式的表格不会在页面上延伸?在 latex 格式中,它保留在页面中,但我既不需要这种格式,也不需要 html .我希望输出文件为.pdf. 我知道在此处 a>,但是我的问题是特定于 markdown 格式的.如果您觉得这是重复的,请合并问题.

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.

可复制的示例:

---
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会使您更接近,但事实证明此参数将采用负整数,因此

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.

这篇关于减少用kable(,format ='markdown')创建的表中各列之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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