在 R Markdown kableExtra 脚注中制作 URL 超链接

问题描述

我正在准备一个 R Markdown 脚本来制作 pdf(使用 tinytex)。 我有一个来自 kableextra 的表格,其中包含一个 footnote(),我想要超链接的 URL。

我知道如何在 tex 中加粗、斜体、删除线文本,但是超链接的 URL?

这是一个例子:

enter image description here

脚注可以链接但不会显示为蓝色,也不会嵌入“来源”标题

好的 - 因为这是降价,所以我会以不同的方式发布:

YAML:

output: pdf_document
header-includes:
   - \usepackage{hyperref}
   - \hypersetup{
        colorlinks=true,urlcolor=cyan}

设置

```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

带有 kableextrafootnote() 网址的部分

## URL in Text Chunk
This a URL <http://rmarkdown.rstudio.com>.

脚注中的节表和 URL

## URL in `kableExtra()` Footnote
```{r,echo=FALSE,warning=FALSE}
library(kableExtra)

kable(head(mtcars),booktabs = T,linesep = "") %>%
  footnote(general="http://rmarkdown.rstudio.com",general_title = "Source: ") %>%
  kable_styling(latex_options = c("striped","hold_position"))

enter image description here

解决方法

我想通了。

我需要改变:

footnote(general="http://rmarkdown.rstudio.com",general_title = "Source: ")

到: footnote(general="\\\\url{http://rmarkdown.rstudio.com}",general_title = "Source: ",footnote_as_chunk = T,escape=F)

谢谢大家