【问题标题】:Printing from knitr/rmarkdown crops images and introduces linebreaks从 knitr/rmarkdown 打印裁剪图像并引入换行符
【发布时间】:2020-08-06 13:12:56
【问题描述】:

我正在创建一份调查问卷,并希望让用户将结果保存为pdf。

html 看起来不错!但是printing 裁剪了图像,到目前为止没有任何效果。

编辑:我添加了一个关于pagedown包的合适quote,可能描述了问题:

"[...] 尝试从您的 Rmarkdown 文件之一生成 PDF,并通过 PDF 我的意思是那种将图像分解成注释的文档 从一页到另一页的一半,书面文本没有结束 页面的…(是的,我知道你知道我的意思,但是…)”

# YAML
---
output: 
    pdf_document:   #html?
        fig_crop: false                         # doesn't work
---

---
output:
  pagedown::html_paged:                         # doesn't work
    css: ["default-fonts", "default-page", "default"]
---

# CSS line-breaks
<style media="print">
    html, body, p, hr, img { 
    break-after:  avoid !important;             # doesn't work
    break-before: avoid !important;             # doesn't work
    break-inside: always !important;            # doesn't work
    } 
</style>

# Button
<input type="button" value="Print this page" onClick="window.print()">
# Example Plot
     ```{r echo=FALSE, message=FALSE}
    library(ggplot2)
    Plot <- ggplot(mpg, aes(displ, cty)) + geom_point()
    Plot + facet_grid(rows = vars(drv))
    plot.height <- 45
     ```


# Calling the plot (with fig.height)
    ```{r, fig.height=plot.height, strip.white = TRUE} # doesn't work
     plot(Plot)
    ```

这是实现的示例: https://exampleruntest.formr.org 由于某种原因,示例情节没有在情节之前引入换行符,而是在之后。

我希望有人有想法

【问题讨论】:

  • 你试过pagedown这个包了吗?
  • 不,但看起来很有希望!我试试看

标签: r r-markdown knitr


【解决方案1】:

回答我的问题:

  1. 图像裁剪被证明是 Firefox 特有的问题。 解决方案是 this 和 this,而后者通过在 CSS 中添加 display:block; 来解决我的问题

  2. 通过使用this 解决方案用&lt;div&gt;(覆盖默认的&lt;p&gt;)包装绘图图像来删除标题后的分页符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-02-24
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多