gpt4 book ai didi

r - 在 Rmarkdown 和 knitr 中同时使用 in_header 和 header_includes

转载 作者:行者123 更新时间:2023-12-03 18:07:01 26 4
gpt4 key购买 nike

我有一个很长的 .txt 文件,其中包含我想在 Rmarkdown 文件中使用的包和设置。我还想根据 R 计算的输出向标题添加语句。在这种特殊情况下,我想添加一个位于另一个目录中的标题图形,如下所示:

working directory
|--- reports
|----| my_report.Rmd
|--- www
|----| image.png

所以 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")`}}

如果只包含其中一个语句(in_header 或 header-includes),它们就可以正常工作。但是当我同时使用它们时, header-includes 的内容似乎被覆盖了 .下面的文件中给出了一个示例,在检查生成的 .tex 文件时,我发现 \usepackage{fancyhdr}位于标题中,但没有提及 `\titlegraphic' 表达式。

头文件.txt
\usepackage{fancyhdr}

例子.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

最佳答案

我认为你可以做的就是把所有东西都放在 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}
---

它有效吗?我无法完全重现您的示例。

关于r - 在 Rmarkdown 和 knitr 中同时使用 in_header 和 header_includes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45303545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com