R Markdown PDF 和 fancyhdr - 如何向页脚添加特殊字符和 link

R Markdown PDF and fancyhdr - how to add special characters and link to footer

我正在尝试创建一个 R Markdown PDF 输出,其页脚在左侧包含一个徽标,在右侧包含另一个徽标,在中间包含一些文本。当我没有特殊字符时,中心文本似乎工作正常。所以我有两个问题:

  1. 如何在页脚中添加特殊字符(例如破折号、& 符号和正斜杠)?
  2. 如何将网站添加为超链接?

如果我的代码只能部分重现,我深表歉意。不知道怎么加图


title: "PDF Outpuf File"
output: pdf_document
fontsize: 11pt
header-includes:
-   \usepackage{graphicx}
-   \usepackage{fancyhdr}
-   \pagestyle{fancy}
-   \fancyfoot[L]{\includegraphics[height=2cm]{images/logo1.png}}
-   \fancyfoot[C]{Data source: 2014-2016 data, A & B research center in the School of Something at the University of Someplace. For more information visit this link: www.google.com}
-   \fancyfoot[R]{\includegraphics[height=2cm]{images/logo2.png}}
-   \fancypagestyle{plain}{\pagestyle{fancy}}
---

我不太清楚你所说的特殊字符是什么意思,但我会尽力回答。

请注意,您的 yaml header 需要正确构建。因此,我认为您需要向 yaml header 添加空格(或可能是制表符)以确保它按照您希望的方式进行解析。

我创建了第二个文件 header.tex,其中包含以下文本:

\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{Data source: 2014-2016 data, A \& B research center in the School of Something at the University of Someplace. For more information visit this link: \url{www.google.com}}
\fancypagestyle{plain}{\pagestyle{fancy}}

然后我创建了一个只有 yaml 的 Rmd 文件 header:

---
title: "PDF Outpuf File"
output: 
  pdf_document:
    includes:
      in_header: header.tex
    keep_tex: true
---

请注意,我 'indent' 在嵌套的 yaml 字段 'output' 的每一层都增加了两个空格。

RStudio 在这里有一个有用的文档:https://rmarkdown.rstudio.com/pdf_document_format.html#overview

如果 "special character" 你指的是 & 符号,请注意 Latex 需要“\”来转义 & 符号,因为常规的“&”在 Latex 中还有另一个用途。

希望对您有所帮助。如果没有帮助,请指出我的错误。

您可以像“\url{google.com}”一样将 url 编码为超链接,不带引号,如我的示例所示。