简体   繁体   中英

Adding a footnote in rmarkdown header

I have some issues with adding a footnote in the YAML header. Without that footnote in the header, the knit execution works well. However, adding a footnote in a different section of the document does not cause an error.

Any piece of advice is highly appreciated.

---
title: "Document1"
author: "Test^[this is a test]"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
latex_engine: xelatex    
---

Error:

! Argument of \reserved@a has an extra }.
<inserted text> 
                \par 
l.76 \author{Test\footnote{this is a test}}

sessionInfo()

R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.7.9 zoo_1.8-8       magrittr_1.5    knitr_1.28      forcats_0.5.0  
 [6] stringr_1.4.0   dplyr_1.0.0     purrr_0.3.4     readr_1.3.1     tidyr_1.1.0    
[11] tibble_3.0.1    ggplot2_3.3.2   tidyverse_1.3.0

loaded via a namespace (and not attached):
 [1] tinytex_0.24     tidyselect_1.1.0 xfun_0.14        haven_2.3.1     
 [5] lattice_0.20-41  colorspace_1.4-1 vctrs_0.3.1      generics_0.0.2  
 [9] htmltools_0.5.0  yaml_2.2.1       utf8_1.1.4       blob_1.2.1      
[13] rlang_0.4.6      pillar_1.4.4     glue_1.4.1       withr_2.2.0     
[17] DBI_1.1.0        dbplyr_1.4.4     modelr_0.1.8     readxl_1.3.1    
[21] lifecycle_0.2.0  munsell_0.5.0    gtable_0.3.0     cellranger_1.1.0
[25] rvest_0.3.5      evaluate_0.14    fansi_0.4.1      highr_0.8       
[29] broom_0.5.6      Rcpp_1.0.4.6     backports_1.1.7  scales_1.1.1    
[33] jsonlite_1.6.1   fs_1.4.1         hms_0.5.3        digest_0.6.25   
[37] stringi_1.4.6    grid_4.0.1       cli_2.0.2        tools_4.0.1     
[41] crayon_1.3.4     pkgconfig_2.0.3  ellipsis_0.3.1   xml2_1.3.2      
[45] reprex_0.3.0     assertthat_0.2.1 rmarkdown_2.3.1  httr_1.4.1      
[49] rstudioapi_0.11  R6_2.4.1         nlme_3.1-148     compiler_4.0.1

You can do it this way:

---
title: "Document1"
author: "Test[^note]"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
latex_engine: xelatex    
---

[^note]: this is a test


Generally, here is how footnotes are defined in pandoc markdown :

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

Subsequent paragraphs are indented to show that they

belong to the previous footnote.

    { some.code }

The whole paragraph can be indented, or just the first
line.  In this way, multi-paragraph footnotes work like
multi-paragraph list items.

This paragraph won't be part of the note, because it isn't indented.


is it happening if you try rmarkdown::render('~/test_.rmd', encoding = 'UTF-8') ? What is sessionInfo() results?

You can do it this way

---
title: "Untitled"
author: |
  "anonymous\footnote{"no one knows me"}
output: pdf_document
---

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM