代码之家  ›  专栏  ›  技术社区  ›  Benjamin Telkamp

脚注中使用knitr和kableExtra的公式或符号

  •  3
  • Benjamin Telkamp  · 技术社区  · 6 年前

    有人知道如何在表格脚注的句子中放置公式、奇怪的字符或斜体字吗?

    我正在用Rmarkdown和kableExtra创建一个pdf文件。但是像这样的 $Y_{t-1}$ $p < .001$ (因为我想要 p 斜体)不起作用。或者我真的应该学习xtable吗?

    1 回复  |  直到 6 年前
        1
  •  8
  •   jay.sf    6 年前

    诀窍在于 1. 四次转义latex代码和特殊字符,例如。 \\\\frac ,则, 2. 设置选项的步骤 escape=FALSE 在里面 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)
    ```
    

    收益率: enter image description here