使用Rmd pdf的自定义模板而不更改当前设置 [英] Using a custom template for Rmd pdf without changing current setup
问题描述
我最近了解到,修改Rmd
pdf报告的默认(Pandoc?)模板可以访问一些简洁的自定义内容.
I have recently learned that modifying the default (Pandoc?) template for a Rmd
pdf report gives access to some neat customisation.
因此,为了修改默认模板,我首先使用以下命令将其移动到我的工作目录中:
So in order to modify the default template I first move it to my working directory using:
file.copy(system.file("rmd/latex/default-1.17.0.2.tex", package ="rmarkdown"), "template.tex")
下一步,我键入Rmd
文件:
---
output:
pdf_document:
template: template.tex
keep_tex: true
latex_engine: xelatex
includes:
in_header: in_header.tex
number_sections: true
---
This is a rmd kind of document.
in_header.tex
仅包含一行
\geometry{a4paper, top=38mm, left=45mm, right=45mm}
我首先只想按原样使用模板运行Rmd
文件(希望没有更改),但是如果且仅当我包含模板时,报表无法编译-否则,运行时将不带模板一个问题.
I first just want to run the Rmd
file with the template as is (expecting no change) but the report fails to compile if and only if I include the template - otherwise it runs without an issue.
错误是
! Undefined control sequence.
l.58 \geometry
[...]
问题
如何使用template参数在我的工作文件夹中的可编辑模板上构建,而不会对当前设置进行任何其他更改.
How can I use the template argument to build on an editable template in my working folder without causing any other change to my current setup.
信息
> R.Version()[["version.string"]]
[1] "R version 3.5.1 (2018-07-02)"
> packageVersion("rmarkdown")
[1] ‘1.10’
> packageVersion("knitr")
[1] ‘1.20’
推荐答案
As you are already driving this from R, you may as well use the (excellent) example set up by the rticles package which provides a larged number of LaTeX customizations for (academic) papers.
然后您就可以运行它们了.例如,在过去两年中,我添加了以下软件包:
And you can then run with that them. For example, over the last two years I added these packages:
- tint for a modern 'Tufte-alike' writeup
- pinp for very nice two-column pdf vignettes
- link for LaTeX letters and some extra
- binb for variants of beaner packages
这允许您
- 设置自定义
template.tex
- 包括所需的任何LaTeX类文件/样式文件
- 以编程方式设置选项
我发现这比复制我以前做过的节(例如幻灯片)更好.
I find this preferable to copying stanzas around which I did previously (eg for slides).
这篇关于使用Rmd pdf的自定义模板而不更改当前设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!