Home > Back-end >  Is is possible to embed a link in kable table caption or footnote?
Is is possible to embed a link in kable table caption or footnote?

Time:09-13

I am curious if it is possble to embedd to link in a kable table caption or footnote when generating a PDF. Here is what I have tried but the following does not render the link.


    ---
    title: "test"
    output: pdf_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
    ```

```{r}

    suppressPackageStartupMessages({
    library(tidyverse)
    library(kableExtra)
    })
    
    url  <- "\\href{https://www.statology.org/iris-dataset-r/}{Iris Dataset}"
    
    kbl(iris[1:5,],align = "l", digits = 2, booktabs = TRUE, longtable = TRUE,
        escape = FALSE) %>%
      kable_styling(
        latex_options = c("striped", "hold_position","repeat_header",
                          font_size = 16, pdf_font = "arial"))%>%
      footnote(general=paste('How can I click this as a pdf?', url, '.'),
               footnote_as_chunk = T) %>%
      column_spec(1:5, width = "2cm") 

enter image description here

CodePudding user response:

You have to use four slashes and the option escape=FALSE in the footnote function:

url  <- "\\\\href{https://www.statology.org/iris-dataset-r/}{Iris Dataset}"
    
  ...... %>%
    footnote(general=paste('How can I click this as a pdf?', url, '.'),
               footnote_as_chunk = TRUE, escape = FALSE)
  • Related