RMarkdown YAML 部分将作者的超链接电子邮件添加到页脚
RMarkdown YAML section add author's hyperlink email to footer
在 RMarkdown 文件的 YAML 部分,我想写下作者的姓名和电子邮件地址,并且只出现在文档的页脚中。这里有一个概念的例子(代码实际上没有运行):
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
after_body:
author: Apple Pie [I want this to be the email hyperlink]
email: apple.pie@bakery.com [but this can also be the hyperlink]
---
我的文件结构:
我有一个名为 rainbow_folder 的主文件夹。在 rainbow_folder 中有两个文件夹,名为 red_folder(我的工作目录)和 blue_folder。红色文件夹包含我的 .Rmd 文件,蓝色文件夹包含其他文件(例如 header_logo.html - 在我的 YAML 中使用 before_body)
编辑:我的输出必须是 html。
相关搜索:
我更喜欢一种不会强迫我更改 pandoc 模板的解决方案。
我也尝试了此 post 中的页脚和页眉解决方案。但是,我不想要更改 html 文件中作者姓名的解决方案。我希望我的输出看起来类似于此 post 中的图像。
https://holtzy.github.io/Pimp-my-rmd/#footer_and_header
编辑:修改解决方案以将其放在正文末尾
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
params:
name: Apple Pie
email: applepie@bakery.com
---
{r your_code_here}
df %>% dput()
<p>Author: `r params$name` </p>
<p>Email: `r params$email` </p>
这是一个选项。您可以在降价文件的 YAML
部分使用 latex
包来添加带有超链接电子邮件的页脚注释。 fancyhdr
包用于页脚,hyperref
包用于电子邮件的超链接。此选项是在 pdf markdown 中创建的。您可以使用以下代码:
---
title: "My Title"
author: "Apple Pie"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{hyperref}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{\href{mailto:apple.pie@bakery.com}{Apple Pie}}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
\thispagestyle{fancy}
输出如下所示:
如您所见,脚注位于页面底部,如果单击它,您将直接转到该邮件。
后面的正文包含不是那样工作的。它期望包含 html 片段的文件名作为页脚包含在内,因为编织过程被编程为将该文件名发送到 Pandoc 的 --include-after-body
选项。这是 Pandoc User's Guide.
中的相关部分
我认为这是一种符合您想做的事情的方法。它使用 parameterized reporting。您的 Rmarkdown 文件可以像这样开始:
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
after_body: ../blue_folder/after.html
self_contained: false
params:
github: holtzy
author: Yan Holtz
email: Yan.holtz.data@gmail.com
twitter: r_graph_gallery
linkedin: yan-holtz-2477534a
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
writeLines(
sprintf(
'
<hr />
<div class="footer">
<p style="text-align: center;">A work by <a href="https://github.com/%s/">%s</a></p>
<p style="text-align: center;"><span style="color: #808080;"><em><a href="mailto:%s">%s</a></em></span></p>
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Add font awesome icons -->
<p style="text-align: center;">
<a href="https://twitter.com/%s?lang=en" class="fa fa-twitter"></a>
<a href="https://www.linkedin.com/in/%s/" class="fa fa-linkedin"></a>
<a href="https://github.com/%s/" class="fa fa-github"></a>
</p>
</div>
',
params$github,
params$author,
params$email,
params$email,
params$twitter,
params$linkedin,
params$github
),
'../blue_folder/after.html'
)
```
这里的做法是在编织过程中,将参数值代入格式字符串,写到你的“blue_folder”中一个名为“after.html”的新文件中。然后这个 html 片段包含在你的 Rmarkdown 正文之后。
结果如下所示:
这种方法的一个警告是我需要将文档设置为不是 self-contained 和 self_contained: false
以便我可以使用外部 css 来获取 font-awesome 图标。
当然,您可以根据自己的喜好编辑 html 片段,也许可以找到一种不同的方式来加载 font-awesome,允许默认 self-contained 编织。
在 RMarkdown 文件的 YAML 部分,我想写下作者的姓名和电子邮件地址,并且只出现在文档的页脚中。这里有一个概念的例子(代码实际上没有运行):
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
after_body:
author: Apple Pie [I want this to be the email hyperlink]
email: apple.pie@bakery.com [but this can also be the hyperlink]
---
我的文件结构: 我有一个名为 rainbow_folder 的主文件夹。在 rainbow_folder 中有两个文件夹,名为 red_folder(我的工作目录)和 blue_folder。红色文件夹包含我的 .Rmd 文件,蓝色文件夹包含其他文件(例如 header_logo.html - 在我的 YAML 中使用 before_body)
编辑:我的输出必须是 html。
相关搜索:
我更喜欢一种不会强迫我更改 pandoc 模板的解决方案。
我也尝试了此 post 中的页脚和页眉解决方案。但是,我不想要更改 html 文件中作者姓名的解决方案。我希望我的输出看起来类似于此 post 中的图像。 https://holtzy.github.io/Pimp-my-rmd/#footer_and_header
编辑:修改解决方案以将其放在正文末尾
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
params:
name: Apple Pie
email: applepie@bakery.com
---
{r your_code_here}
df %>% dput()
<p>Author: `r params$name` </p>
<p>Email: `r params$email` </p>
这是一个选项。您可以在降价文件的 YAML
部分使用 latex
包来添加带有超链接电子邮件的页脚注释。 fancyhdr
包用于页脚,hyperref
包用于电子邮件的超链接。此选项是在 pdf markdown 中创建的。您可以使用以下代码:
---
title: "My Title"
author: "Apple Pie"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{hyperref}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{\href{mailto:apple.pie@bakery.com}{Apple Pie}}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
\thispagestyle{fancy}
输出如下所示:
如您所见,脚注位于页面底部,如果单击它,您将直接转到该邮件。
后面的正文包含不是那样工作的。它期望包含 html 片段的文件名作为页脚包含在内,因为编织过程被编程为将该文件名发送到 Pandoc 的 --include-after-body
选项。这是 Pandoc User's Guide.
我认为这是一种符合您想做的事情的方法。它使用 parameterized reporting。您的 Rmarkdown 文件可以像这样开始:
---
title: My Title
output:
html_document:
include:
before_body: ../blue_folder/header_logo.html
after_body: ../blue_folder/after.html
self_contained: false
params:
github: holtzy
author: Yan Holtz
email: Yan.holtz.data@gmail.com
twitter: r_graph_gallery
linkedin: yan-holtz-2477534a
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
writeLines(
sprintf(
'
<hr />
<div class="footer">
<p style="text-align: center;">A work by <a href="https://github.com/%s/">%s</a></p>
<p style="text-align: center;"><span style="color: #808080;"><em><a href="mailto:%s">%s</a></em></span></p>
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Add font awesome icons -->
<p style="text-align: center;">
<a href="https://twitter.com/%s?lang=en" class="fa fa-twitter"></a>
<a href="https://www.linkedin.com/in/%s/" class="fa fa-linkedin"></a>
<a href="https://github.com/%s/" class="fa fa-github"></a>
</p>
</div>
',
params$github,
params$author,
params$email,
params$email,
params$twitter,
params$linkedin,
params$github
),
'../blue_folder/after.html'
)
```
这里的做法是在编织过程中,将参数值代入格式字符串,写到你的“blue_folder”中一个名为“after.html”的新文件中。然后这个 html 片段包含在你的 Rmarkdown 正文之后。
结果如下所示:
这种方法的一个警告是我需要将文档设置为不是 self-contained 和 self_contained: false
以便我可以使用外部 css 来获取 font-awesome 图标。
当然,您可以根据自己的喜好编辑 html 片段,也许可以找到一种不同的方式来加载 font-awesome,允许默认 self-contained 编织。