【问题标题】:R Summarytools Printing TablesR Summarytools 打印表格
【发布时间】:2020-06-16 03:00:48
【问题描述】:

我正在使用 Rmarkdown 中的 summarytools 包并将其编入 HTML。表格看起来不错,但每当我打印 HTML 文档时,表格的格式(尤其是 ctable)都会关闭。见下图

如您所见,每个单元格中都有这些边框。我相信这与使用默认 bootstrap.css 文件的 RMD 有关,并且在探索该文件后,我发现了一些“@media print”行。有没有人有解决这个问题的快速解决方案,还是我必须更改底层的 bootstrap.css 文件?

谢谢。

【问题讨论】:

  • 除非你找到一种方法来用 CSS 掩盖这些恼人的边框,否则最好的选择是坚持纯文本输出。在未来的某个时候,该软件包可能提供一个替代显示,其中频率和比例在一个单元格中,但这意味着内容对齐不太好。
  • 其他值得尝试的方法:使用 wkhtmltopdf 将 html 文件转换为 pdf 并打印 pdf。免费的 wkhtmltopdf 工具在类似情况下确实有帮助(使用 pandoc 将 html 转换为 pdf 会显示这些边框,而使用 wkhtmltopdf 不会发生这种情况)。

标签: r r-markdown summarytools


【解决方案1】:

我相信这与使用默认 bootstrap.css 的 RMD 有关 文件...

如果是这种情况,您可以尝试使用 st_css(bootstrap = FALSE) 取消 Bootstrap 的 CSS。
此外,您可能会发现将 results = "asis" 包含到 knitr 块选项中会有所帮助。
最后,查看 Dominic 的“使用 Rmarkdown 使用 summarytools 的建议”和关于 ctable() 的部分。根据 Dominic 的“首选渲染方法”method = 'render'

---
title: "Title"
author: "Author"
date: "16/06/2020"
output: 
  html_document:
    toc: TRUE
    toc_float: TRUE
---

```{r setup, include = FALSE}
library(knitr)
library(summarytools)
knitr::opts_chunk$set(results = "asis")
```  

```{r summarytools-css, echo = FALSE}
# with summarytools’ CSS we can cancel Bootstrap’s CSS (both are included by default)
# without it odd layout are expected, especially with dfSummary()
st_css(bootstrap = FALSE)
```

```{r summarytools-rmarkdown, echo = FALSE}    
   ctable(tobacco$gender, tobacco$smoker, style = 'rmarkdown')
```  

```{r summarytools-html, echo = FALSE}    
   print(ctable(tobacco$gender, tobacco$smoker), method = 'render')
```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    相关资源
    最近更新 更多