R 变量作为 Rmarkdown 中的页脚
R variable as footer in Rmarkdown
尽管关于这个主题的问题太多,但我找不到我要找的东西。
我有一个这样的 R 文件
calculation <- 2+6
footer <- sprintf("Nice footer: %s", calculation)
rmarkdown::render("My_Markdown.Rmd",output_format = "pdf_document",
output_file="myfile.pdf")
与My_Markdown.rmd:
---
output:
pdf_document:
number_section: yes
toc: yes
toc_depth: 4
keep_tex: yes
includes:
in_header: header.tex
---
```{r, results='asis'}
cat(calculation)
```
其中 header.tex 加载一些乳胶包。
我想要页脚,作为 pdf 每一页的页脚。就此而言,我尝试了
的几种变体(有或没有“”;在 header.tex 中或单独在 header-includes 中)
\pagestyle{fancy}
\fancyfoot[CO,CE]{`r footer`}
\fancyfoot[LE,RO]{\thepage}
到目前为止,none 成功了。有人有解决方案吗?
当文件传递给 includes
参数时,您不能在其中使用代码块或内联代码。他们不会被评估。
由于 R Markdown 文件是使用脚本生成的,您可以像这样动态创建 header.tex
文件:
calculation <- 2+6
footer <- sprintf("Nice footer: %s", calculation)
writeLines(sprintf(
'\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[CO,CE]{%s}
\fancyfoot[LE,RO]{\thepage}
', footer), "header.tex")
rmarkdown::render("My_Markdown.Rmd",
output_format = "pdf_document",
output_file="myfile.pdf")
不要忘记在 R Markdown 文件中使用 twoside
class:
---
output:
pdf_document:
number_section: yes
toc: yes
toc_depth: 4
keep_tex: yes
includes:
in_header: header.tex
classoption: twoside
---
```{r, results='asis'}
cat(calculation)
```
在代码块之外添加您的乳胶代码并使用“r
”传递变量
\fancyfoot[L]{`r variable_name`}
尽管关于这个主题的问题太多,但我找不到我要找的东西。
我有一个这样的 R 文件
calculation <- 2+6
footer <- sprintf("Nice footer: %s", calculation)
rmarkdown::render("My_Markdown.Rmd",output_format = "pdf_document",
output_file="myfile.pdf")
与My_Markdown.rmd:
---
output:
pdf_document:
number_section: yes
toc: yes
toc_depth: 4
keep_tex: yes
includes:
in_header: header.tex
---
```{r, results='asis'}
cat(calculation)
```
其中 header.tex 加载一些乳胶包。
我想要页脚,作为 pdf 每一页的页脚。就此而言,我尝试了
的几种变体(有或没有“”;在 header.tex 中或单独在 header-includes 中)\pagestyle{fancy}
\fancyfoot[CO,CE]{`r footer`}
\fancyfoot[LE,RO]{\thepage}
到目前为止,none 成功了。有人有解决方案吗?
当文件传递给 includes
参数时,您不能在其中使用代码块或内联代码。他们不会被评估。
由于 R Markdown 文件是使用脚本生成的,您可以像这样动态创建 header.tex
文件:
calculation <- 2+6
footer <- sprintf("Nice footer: %s", calculation)
writeLines(sprintf(
'\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[CO,CE]{%s}
\fancyfoot[LE,RO]{\thepage}
', footer), "header.tex")
rmarkdown::render("My_Markdown.Rmd",
output_format = "pdf_document",
output_file="myfile.pdf")
不要忘记在 R Markdown 文件中使用 twoside
class:
---
output:
pdf_document:
number_section: yes
toc: yes
toc_depth: 4
keep_tex: yes
includes:
in_header: header.tex
classoption: twoside
---
```{r, results='asis'}
cat(calculation)
```
在代码块之外添加您的乳胶代码并使用“r
”传递变量
\fancyfoot[L]{`r variable_name`}