我正在使用output = pdf和xelatex从Rmd文件生成pdf . 有些数字较大,覆盖整个页面 . 因此生成的pdf会创建一个空页面 . 为了避免这种情况,我决定使用out.width = '90%'来减小数字的大小 .

这是我的.Rmd文件:

---
title: "test out width"
author: "Courvoisier"
date: "8 November 2016"
output:
  pdf_document:
    fig_height: 8
    fig_width: 12
    keep_tex: yes
    latex_engine: xelatex
    number_sections: yes
    toc: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

Including Plots

plot(pressure)
plot(pressure)

我用render来创建pdf . 这是.R代码:

```java
rm(list = ls())
library(knitr)
library(rmarkdown)

RmdFile = "testoutwidth.Rmd"
outputpdfFilePathoutPdf = "testoutwidth.pdf"
renderoutputpdfFilePath = render(input = RmdFile, output_file = outputpdfFilePathoutPdf)

这工作正常,并创建以下.TeX代码的数字:

\includegraphics{testoutwidth_files/figure-latex/pressure-1.pdf}

\includegraphics[width=0.9\linewidth]{testoutwidth_files/figure-latex/pressure2-1}

但是,在渲染函数中选择output_dir时,例如:

renderoutputpdfFilePath = render(input = RmdFile, output_dir = "out pdf/", output_file = outputpdfFilePathoutPdf)

生成的.TeX中的includegraphics命令变为

\includegraphics{C:/work/testRenderRmd/out pdf/testoutwidth_files/figure-latex/pressure-1.pdf}

\includegraphics[width=0.9\linewidth]{C:\work\testRenderRmd\out pdf\testoutwidth_files/figure-latex/pressure2-1}

在第二个\ includegraphics(具有[width = 0.9 \ linewidth]的那个)中,路径分隔符是“\”而不是“/”,因此乳胶编译失败 . (它给出C:\ work ...而不是C:/ work / ...) .

我应该用什么来解决这个问题?

谢谢

注意:似乎在rmarkdown github上有一个问题:https://github.com/rstudio/rmarkdown/issues/808