Formula's or symbols in footnotes using knitr and kableExtra

强颜欢笑 提交于 2019-12-09 08:33:30

The trick is 1. to escape latex code and special characters four times, e.g. \\\\frac, 2. to set option escape=FALSE in footnote().

---
title: "Untitled"
output: pdf_document
---

```{r tab}
library(knitr)
library(kableExtra)
df <- data.frame(v1=rnorm(6), v2=runif(6), v3=rbinom(6, 1, .33), 
                 row.names=LETTERS[1:6])
kable(df, "latex", align="c", booktabs=TRUE) %>%
footnote(general=c("$a^2+b^2=c^2,$",     
                   "$\\\\sigma^2=\\\\frac{1}{n-1}\\\\sum_{i=1}^n(x_i-\\\\bar{x})^2;$", 
                   "1,000 \\\\$;", "100\\\\%."),
         number=c("Hello\ there! \\\\textit{Hello\ there!}"),
         footnote_as_chunk=TRUE, 
         escape=FALSE)
```

Yields:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!