Flo*_*ian 5 latex r knitr r-markdown
我有一个很长的.txt文件,其中包含我想在我的Rmarkdown文件中使用的包和设置.我还想根据R计算的输出向标题添加语句.在这种特殊情况下,我想添加一个位于另一个目录中的titlegraphic,如下所示:
working directory
|--- reports
|----| my_report.Rmd
|--- www
|----| image.png
Run Code Online (Sandbox Code Playgroud)
所以Rmarkdown文件的标题如下所示:
output:
beamer_presentation:
keep_tex: true
includes:
in_header: header.txt
header-includes:
- \titlegraphic{\includegraphics[width=0.3\paperwidth]{`r paste0("dirname(getwd()),"image.png")`}}
Run Code Online (Sandbox Code Playgroud)
如果只包含其中一个语句(in_header或header-includes),它们可以正常工作.但是当我同时使用它们时,header-includes的内容似乎被覆盖了.下面的文件中给出了一个示例,在检查生成的.tex文件时,我发现它\usepackage{fancyhdr}位于标题中,但没有提到`\ titlegraphic'表达式.
header.txt
\usepackage{fancyhdr}
Run Code Online (Sandbox Code Playgroud)
example.Rmd
title: Example 1
output:
beamer_presentation:
keep_tex: true
includes:
in_header: header.txt
header-includes:
\titlegraphic{\includegraphics[width=0.3\paperwidth]{`r paste0("just_an_example_","logo.png")`}}
---
### This is a test
Run Code Online (Sandbox Code Playgroud)
F. *_*ivé 11
我想你能做的就是把所有东西放进去header-includes:
---
title: Example 1
output:
beamer_presentation:
keep_tex: true
header-includes:
- \titlegraphic{\includegraphics[width=0.3\paperwidth]{`r paste0("just_an_example_","logo.png")`}}
- \input{header.txt}
---
Run Code Online (Sandbox Code Playgroud)
它有用吗?我不能完全重现你的例子.