繁体   English   中英

KableExtra 数学符号

[英]KableExtra math symbols

如何在 kable 中插入“等于或大于”符号? 在下面的小 rmarkdown 文档中,我根据一些互联网建议尝试了两种不同的方法,但都不起作用。 我确实尝试过'escape = FALSE'的论点,但它也不起作用。 感谢您的任何指点...


title: "Math symbols in column headers"
date: "January 15, 2020"
output: pdf_document
---

```{r}
library(kableExtra)
library(knitr)

a <- structure(list(MLE = c(0.0839, 0.2082, 0.4194, 0.8237, 1.6201
), MME = c(0.0839, 0.2082, 0.4194, 0.8234, 1.6147)), class = "data.frame", row.names = c(NA, 
5L)) 

colnames(a) <- c("abundance of\n White Sharks\n $\\\\geq$ 40 inches","Percentage of \n White shark in 
the population\n $\\\\geq{40}$ inches")
```

```{r}
kable(a, "latex", booktabs = T)

```

这就是我得到的...

在此处输入图片说明

您需要在 Markdown 文件中以\\geq结尾。 为此,您在 R 字符串中输入"\\\\geq" ,并在对kable()的调用中指定escape = FALSE 那是,

---
title: "Math symbols in column headers"
date: "January 15, 2020"
output: pdf_document
---

```{r}
library(kableExtra)
library(knitr)

a <- structure(list(MLE = c(0.0839, 0.2082, 0.4194, 0.8237, 1.6201
), MME = c(0.0839, 0.2082, 0.4194, 0.8234, 1.6147)), class = "data.frame", row.names = c(NA, 
5L)) 

colnames(a) <- c("Abundance of\n White Sharks\n $\\geq 40$ inches","Percentage of \n White shark in 
the population\n $\\geq 40$ inches")
```

```{r}
kable(a, "latex", booktabs = T, escape = FALSE)

``` 

这给了我

在此处输入图片说明

要尊重换行符,您需要使用kableExtralinebreak函数,即如下所示:

colnames(a) <- linebreak(c("Abundance of\n White Sharks\n $\\geq 40$ inches",
                         "Percentage of \n White shark in the population\n $\\geq 40$ inches"))
kable(a, "latex", booktabs = TRUE, escape = FALSE, align = "c") 

这给出了这个输出:

截图 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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