有没有办法为pdf制作没有线条/边框的kable? [英] Is there a way to make a kable without lines/borders for pdf?

查看:68
本文介绍了有没有办法为pdf制作没有线条/边框的kable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个闪亮的应用程序,该应用程序可以生成并发送包含经过处理的数据的 pdf 报告.问题是我无法让表格布局看起来像客户希望的那样.

I'm working on a shiny-app that produces and sends a pdf-report, containing the wrangled data. The problem is that I can't get the table layout to look as the client want it to look.

客户希望表格除了最后一行之外没有线条/边框,这在 kable 和/或 kableExtra 中可能吗?请不要包含其他包的答案,因为我知道 xtable 的答案.

The client wants the tables to lack lines/borders except ontop of the last row, is this possible in kable and/or kableExtra? No answers containing other packages please, as I'm aware that of xtable.

table.tbl <- tibble(var1 = c("entry 1", "entry 2", "entry 3", "entry 4"),
                var2 = c(2000, 1000, 3000, 200),
                var3 = c(3000, 2000, 4000, 100))

table.tbl %>% 
  kable("latex", 
        booktabs = T) %>% 
  row_spec((table.tbl %>% 
             nrow()-1), hline_after = T)

推荐答案

我认为 kable 的目的是超级简单,因此在设计上缺少这样的功能.也就是说,我想出了一个非常痛苦的解决方案.要点是我将边框颜色设置为白色(我假设您的页面是白色),然后在需要时将线条颜色切换为非白色(在我的示例中为红色),然后再回到白色.

I think kable is meant to be super simple and so lacks features like this by design. That said, I have come up with an absurdly painful solution. The gist is that I set border colours to white (I'm assuming your page is white), then switch line colours to non-white (red in my example) when needed, then back to white again afterwards.

首先,将以下内容添加到您的 YAML 标头中:

Initially, add the following to your YAML header:

header-includes:
  - \usepackage{colortbl}

接下来,在您的文档中添加:

Next, in your document add:

\arrayrulecolor{white}

要呈现表格使用:

library(tidyverse)
library(knitr)
library(kableExtra)

table.tbl <- tibble(var1 = c("entry 1", "entry 2", "entry 3", "entry 4"),
                var2 = c(2000, 1000, 3000, 200),
                var3 = c(3000, 2000, 4000, 100))
table.tbl %>% 
  kable(format = "latex") %>%
  row_spec((table.tbl %>% 
             nrow()-1), extra_latex_after = "\\arrayrulecolor{red}") %>% 
  row_spec((table.tbl %>% 
             nrow()), extra_latex_after = "\\arrayrulecolor{white}")

给予,

这篇关于有没有办法为pdf制作没有线条/边框的kable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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