【发布时间】:2016-10-19 01:57:38
【问题描述】:
我正在制作一个 Rmd 文档,其中还包含一些情节。它应该同时导出到 otd 和 pdf。一些数字应该足够小,以使其中两个在生成的 odt 中彼此相邻。
我通过
编织文档Rscript -e "require(knitr); require(markdown); knit('Test_Markdown.Rmd', 'Test_Markdown.md')"
在 Rmd 中有一个如下所示的情节:
```{r plottestnormal, fig.path = ".", fig.width = 6, fig.height = 6, dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
我希望绘图是一半大小——但要按比例缩放!
这得到正确的大小,但不是缩放:
```{r plottestsmall, fig.path = ".", fig.width = 3, fig.height = 3, dpi = 600, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
据我从the opiton description 了解到,以下内容应该符合我的意思,但它不起作用。
```{r plottestscaled, fig.path = ".", fig.width = 6, fig.height = 6, out.width = 3, out.height = 3, dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
这会在生成的 *md 文件中生成一个 html img 标签:
<img src=".plottestscaled-1.png" title="plot of chunk plottestscaled" alt="plot of chunk plottestscaled" width="3" height="3" />
而且编译时不会在 pdf 和 odt 中显示
pandoc -f markdown "Test_Markdown.md" -o "Test_Markdown.odt"
pandoc -t latex "Test_Markdown.md" -o "Test_Markdown.pdf"
我已经看到this issue 这对我没有进一步的帮助。
我错过了什么?
编辑:
感谢@Yihui,这现在适用于 LaTeX-> pdf 和(可能 - 未经测试)适用于 html。
我说得对吗,*.odt 或 *.docx 导出不支持 out.width 和 out.height?
如果是,它们不适合我的原因可能是什么?
如果不是,我怎样才能在*.odt 中实现相同的效果(比例图)?
(我想导出到pdf 和odt,因此任何解决方案都可以同时涵盖(至少)这两个。)
这是一个完整的文档,显示了我在通过 rmarkdown::render("Test_Markdown.Rmd", "all") 处理时遇到的问题。
---
title: Scale plot in Rmd
output:
pdf_document:
latex_engine: xelatex
odt_document:
keep_md: true
---
```{r plottestscaled, fig.path = "./", fig.width = 6, fig.height = 6, out.width = "3in", out.height = "3in", dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
```
编辑2:
到目前为止,我的“最佳”解决方案是禁用odt 输出中的缩放并在办公室手动重新缩放绘图。不过,不是很可重复......
```{r plottestscaled, fig.path = "./", fig.width = 6, fig.height = 6, out.width=switch(opts_knit$get("rmarkdown.pandoc.to"), latex = "3in", NULL), out.height=switch(opts_knit$get("rmarkdown.pandoc.to"), latex = "3in", NULL), dpi = 300, dev = "png", dev.args = list(type = "cairo")}
plot(1:10, 1:10)
【问题讨论】:
标签: r markdown knitr r-markdown