表格太宽,无法容纳Markdown生成的PDF [英] Table way too wide to fit in Markdown generated PDF

查看:162
本文介绍了表格太宽,无法容纳Markdown生成的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Rmarkdown从SQL查询到pdf显示表格.但是,我得到的表太宽了,不能容纳在文档中.

I am trying to display a table from an SQL query to a pdf by using Rmarkdown. However, the table I get is too wide and it does not fit in the document.

建议我使用Pander程序包,因此我尝试使用在控制台上非常有用的pandoc.table()函数,但是由于某些原因,它阻止了我的文档在Rmarkdown中呈现.

I have been recommended to use the Pander package, and so I tried to use the pandoc.table() function which works greatly on the console, but for some reason it stops my document from rendering in Rmarkdown.

代码看起来像这样:

rz = dbSendQuery(mydb, "select result.id result_id, company.id company_id, (...)")
datz = fetch(rz, n=-1)

这是一个很长的查询,但是,正如我所说的,它在MySQL和R控制台上都可以工作(在RStudio上工作).

It is a very long query but, as I said, it works both on MySQL and R console (working on RStudio).

所以,当我这样做

kable(datz, "latex", col.names = c(colnames(datz)), caption=paste('This is a sample table')) %>% kable_styling(latex_options = "striped") %>% column_spec(1, bold = T, color = "red"))

打印的结果太宽,无法容纳在PDF中.

the results that get printed are too wide to fit in the PDF.

我不知道该如何解决.我尝试使用pander包中的pandoc.tables(),但是与kable中的选项相比,结果的格式似乎非常谦虚.

I do not know how can I solve this. I tried with pandoc.tables() from pander package, but the format of the result seems to be very humble compared to the options I have in kable.

推荐答案

您必须使用kableExtra中的scale_down选项.当scale_down选项太宽时,它将使您的表格适合一页.警察字体也将减少.

You have to use the scale_down option from kableExtra. The scale_down option is going to fit your table on one page when it is too wide. The police font will also be reduce.

以下是您可以使用的代码示例:

Here is an example of the code you could use :

kable(your_dt, "latex", booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down"))

这篇关于表格太宽,无法容纳Markdown生成的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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