【问题标题】:KableExtra math symbolsKableExtra 数学符号
【发布时间】:2020-01-16 19:22:45
【问题描述】:

如何在 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)

```

这就是我得到的......

【问题讨论】:

    标签: r r-markdown kable kableextra


    【解决方案1】:

    您需要在 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)
    
    ``` 
    

    这给了我

    要遵守换行符,您需要使用kableExtra 中的linebreak 函数,即类似这样的东西:

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

    给出这个输出:

    【讨论】:

    • 非常感谢。我的列标题很长,如何在此处使用 \n?
    • 查看 kableExtra 包中的小插图“LaTeX 表中换行的最佳实践”:运行 vignette("best_practice_for_newline_in_latex_table")
    • 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多