在R-Markdown中使用knitr和kableExtra的表格单元格中的胶乳公式或符号,

Ben*_*amp 6 latex symbols r tabular r-markdown

感谢jaySf,我能够创建一个包含漂亮表格的pdf文件,其中的脚注显示了R Markdown,Latex knitrkableExtra(在他的示例下方)公式和符号:

---
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)
```
Run Code Online (Sandbox Code Playgroud)

这导致:

在此输入图像描述

现在我正在努力将符号或公式放在表格的一个实际单元格中.有人可以做一个例子,在一个单元格中显示常规文本,符号公式吗?表格标题中最好也是相同的,其中一个列名称一个一个表格的行名称以及一些编号的脚注引用其中一个单元格或标题或col或行名称中的信息,我很想死拥有一切的例子!非常感谢.

Mar*_*zer 11

当然:请注意escape传递给的论点kable:

---
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])

df$v4 <- c('My formula $\\sum_{i=1}^9$')
kable(df, "latex", align="c", booktabs=TRUE, escape = F, caption = '$\\Gamma$') %>%
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)
```
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

另一个使用斜体列名称和附加标题的示例:

```{r, echo = F}
library(knitr)
library(kableExtra)
df <- data.frame(v1=rnorm(6), v2=runif(6), v3=rbinom(6, 1, .33), 
             row.names=LETTERS[1:6])
df$v4 <- c('My formula $\\sum_{i=1}^9$')

# italic column headers
colnames(df) <- paste0("\\textit{", colnames(df),"}")

kable(df, "latex", align="c", booktabs=TRUE, escape = F, caption = '$\\Gamma$') %>%
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) %>%
  add_header_above(header = c("\\\\textbf{Results} $\\\\Delta$" = 5), escape = F)
```
Run Code Online (Sandbox Code Playgroud)

  • 美丽.这绝对可以帮助很多人在桌子上挣扎! (2认同)
  • 完毕。总是一样。只需在需要的地方添加原始 tex。 (2认同)