如何使用列标题中的希腊字母在rmarkdown中创建表? [英] How to create table in rmarkdown using greek letters in column headers?

查看:107
本文介绍了如何使用列标题中的希腊字母在rmarkdown中创建表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用kablekableExtra在rmarkdown中创建一个表,并且我想在add_header_above函数中放入希腊字母.

I am trying to create a table in rmarkdown with kable and kableExtra and I want to put greek letters in the add_header_above function.

kable(a, format = "latex", booktabs = T, longtable = T) %>% 
kable_styling() %>%
add_header_above(c("n", "$\\alpha$", "Estimates for $\\alpha$" = 4, 
"Estimates for $\\beta$" = 4), align = "l", escape = F)

我尝试像此处一样使用escape = F,但是它似乎不适用于希腊字母.

I tried using escape = F like here, but it seems it doesn't work for greek letters.

我想要我的rmarkdown文档中具有这种样式的表格,并在列标题中添加希腊字母.有没有办法用kablekableExtra甚至使用另一种方法来做到这一点?

I want that style of table in my rmarkdown document with the greek letters in the column headers. Is there a way to do that with kable and kableExtra or even with another method?

我的数据:

a <- structure(list(c("5", "", "", "", ""), c(0.1, 0.25, 0.5, 1, 2
), MLE = c(0.0839, 0.2082, 0.4194, 0.8237, 1.6201), MME = c(0.0839, 
0.2082, 0.4194, 0.8234, 1.6147), UMLE = c(0.1048, 0.2602, 0.5242, 
1.0296, 2.0251), UMME = c(0.1048, 0.2602, 0.5242, 1.0293, 2.0183
), MLE = c(1, 1.0057, 1.0232, 1.0824, 1.2543), MME = c(1, 1.0057, 
1.0232, 1.0824, 1.2551), UMLE = c(0.9994, 1.0019, 1.0077, 1.0233, 
1.0456), UMME = c(0.9994, 1.0019, 1.0077, 1.0233, 1.0476)), .Names = c("", 
"", "MLE", "MME", "UMLE", "UMME", "MLE", "MME", "UMLE", "UMME"
), row.names = c(NA, 5L), class = "data.frame")

推荐答案

您只需要提供一些额外的转义即可.管道中的某些内容会占用\\字符,因此请使用\\\\代替:

You just need to give some extra escapes. Something in your pipeline ate the \\ characters, so use \\\\ instead:

kable(a, format = "latex", booktabs = TRUE, longtable = TRUE) %>% 
  kable_styling() %>%
  add_header_above(c("n", "$\\\\alpha$", "Estimates for $\\\\alpha$" = 4, 
                     "Estimates for $\\\\beta$" = 4), 
                   align = "l", escape = FALSE)

这给出了:

我还将您的TF更改为TRUEFALSE;这是没有必要的 在这里,但这是很好的防御性编程.

I also changed your T and F to TRUE and FALSE; this is not necessary here, but it is good defensive programming.

这篇关于如何使用列标题中的希腊字母在rmarkdown中创建表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆