kable / kableExtra将上标添加到group_rows中的组标签

时间:2018-08-29 05:59:33

标签: r r-markdown knitr kable kableextra

我有一张要使用kable和kableExtra为pdf演示文稿创建的表。我想对行进行分组,并且需要在行组标签中使用上标。我尝试了几种不同的方法。这是到目前为止我尝试过的一些方法的示例。

 {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "views": {
                "$id": "views",
                "type": "array",
                "items": {
                    "$id": "views/items",
                    "type": "object",
                    "properties": {
                        "groups": {
                            "$id": "views/groups",
                            "type": "array",
                            "items": {
                                "$id": "views/groups/items",
                                "type": "object",
                                "properties": {
                                    "tiles": {
                                        "$id": "views/groups/tiles",
                                        "type": "array",
                                        "items": {
                                            "$id": "views/groups/tiles/items",
                                            "type": "object",
                                            "properties": {
                                                "dataStamp": {
                                                    "$id": "views/groups/tiles/dataStamp",
                                                    "type": "integer"
                                                },
                                                "tile_type": {
                                                    "$id": "views/groups/tiles/tile_type",
                                                    "type": "string"
                                                },
                                                "errorCode": {
                                                    "type": "integer",
                                                    "enum": [
                                                        2, 10
                                                    ]
                                                },
                                                "errorText": {
                                                    "type": "string",
                                                    "enum": [
                                                        "seloger", "france24"
                                                    ]
                                                }
                                            },
                                            "if": {
                                                "properties": {
                                                    "tile_type": {
                                                        "enum": ["person"]
                                                    },
                                                    "errorCode": {
                                                        "enum": [2, 10]
                                                    }

                                                },
                                                "required": ["errorCode", "errorText"]
                                            }

                                        }
                                    }
                                },
                                "required": [
                                    "type",
                                    "tiles"
                                ]
                            }
                        }
                    },
                    "required": [
                        "groups"
                    ]
                }
            }
        },
        "required": [
            "views"
        ]
    }
}

我的想法用光了,无法在搜索中找到其他建议。

1 个答案:

答案 0 :(得分:2)

您需要在escape=FALSE调用中使用group_rows()才能解释乳胶命令。您似乎还需要将每个反斜杠加倍(我不太明白为什么)。在那之后,有几个可行的选择:

kable(foo, format = "latex", booktabs = T, row.names = FALSE, linesep = "", escape = FALSE) %>%
  kable_styling(latex_options = c("striped")) %>%
  group_rows("$\\\\text{Group1}^a$", 1, 2, escape = FALSE) %>% 
  group_rows(paste0("Group2\\\\", footnote_marker_alphabet(1), sep = ""), 3, 4, escape = FALSE) %>% 
  # I don't think expression() is helpful, doesn't seem to get converted
  # to latex
  group_rows(expression("Group3"^a), 5, 6) %>% 
  group_rows("Group4\\\\textsuperscript{a}", 7, 8, escape = FALSE)