从 knitr/rmarkdown 打印会裁剪图像并引入换行符

Printing from knitr/rmarkdown crops images and introduces linebreaks

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

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

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

"[...] try to generate PDF from one of your Rmarkdown files, and by a PDF I mean that kind of document where images are note broken into half from page to page and written text does not finish beyond the end of the page… (yeah, I know you know what I mean bu that…)"

# 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 由于某种原因,示例情节没有在情节之前引入换行符,而是在之后。

希望有人出出主意

回答我的问题:

  1. 图像裁剪原来是 firefox 特有的问题。 解决方案是 this and this,而后者通过将 display:block; 添加到 CSS

    来解决我的问题
  2. 通过用 <div> 包装图的图像(覆盖默认 <p>) 使用 this 解决方案。