R Markdown Knitr 转 PDF 代码外边距 [英] R Markdown Knitr to PDF Code Outside Margin
问题描述
我想在文档末尾附上我的全部代码块.代码包括绘图、插入图形、计算等.它的长.这是在我运行了相应章节中的相关代码之后.在这一点上,我不希望代码生成任何结果,而只是简单地显示代码,以便其他人可以检查我所做的事情.
I want to attach the entirety of my code chunks at the end of my document. The code includes plots, inserted graphics, calculations and so forth. It's long. This is after I have run the relevant code in its respective chapters. At this point, I don't want the code to generate any results, but simply show the code so that others can check on what I have done.
这是部分代码的示例:
shapefile1 <- readOGR("./Folder1/Folder2/Folder3", layer = "TM_WORLD_BORDERS-0.3") # Read in world shapefile
当我编译时,它显示在我在 YAML 标头中为我的文档设置的边距之外
When I compile, it shows up outside the margin that I have set for my document in the YAML header like this
geometry: top=2.5cm, bottom=2cm, left=3cm, right=3.5cm
我尝试了以下解决方案:
I have tried the following solutions:
选项 1:
在 RStudio 的 R markdown 中,如何防止源代码跑出 pdf 页面?
```{r, eval=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=60)}
```
选项 2:
https://tex.stackexchange.com/questions/133810/knitr-plotting-outside-边距
```{r, eval=FALSE, out.width=".9\\paperwidth"}
```
都不适合我.我唯一能想到的另一件事是手动缩短代码行,但我确信这不是最好的选择.这是怎么做的?
Neither works for me. The only other thing I can think of is manually making the code lines shorter, but I'm sure that can't be the best option. How is this done?
推荐答案
当我在 R Studio 中使用pdflatex"作为 Latex 引擎时会发生这种情况.当我更改为xelatex"时,这种情况不再发生.但是在降价开始时我也需要这个代码块:
This happens to me when I use "pdflatex" as the Latex Engine in R Studio. When I change to "xelatex", this doesn't happen anymore. But I also need this code chunk in the beggining of the markdown:
library(knitr)
# Set so that long lines in R will be wrapped:
opts_chunk$set(tidy.opts=list(width.cutoff=40),tidy=TRUE)
这篇关于R Markdown Knitr 转 PDF 代码外边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!