作为标题,我试图使用group_rows
函数整理表,如下所示,我在第5列添加了<=
符号(即<=rowid
),但是该列用于group_rows
时无法正确显示该符号,有人可以帮忙吗?谢谢!
---
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{colortbl}
- \usepackage{tikz}
papersize: a4
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
library(dplyr)
library(knitr)
library(kableExtra)
knitr::opts_chunk$set(warning=FALSE, message=FALSE, echo=FALSE)
options(kableExtra.latex.load_packages = FALSE)
```
```{r cars, results='asis'}
data.df <- iris %>%
data.frame %>%
group_by(Species) %>%
filter(row_number()<=3) %>%
mutate(rowid=1:n()) %>%
ungroup %>%
mutate(Species=as.character(Species)) %>%
mutate(Species=paste0('$\\geq$',Species)) %>%
mutate(rowid=paste0('$\\geq$',rowid)) %>%
rename('$\\geq$rowid'='rowid')
data.df %>%
select(-Species) %>%
kable(.,format = 'latex',booktabs=TRUE,escape = FALSE,longtable=TRUE) %>%
group_rows(index = auto_index(data.df$Species)) %>%
kable_styling(latex_options = c('repeat_header','striped','HOLD_position'))
```
答案 0 :(得分:1)
分组的行标题放在\textbf{}
语句中,并且以某种方式在此过程中进行了额外的文本清理。如果您在escape = T
中使用group_rows
并添加多余的反斜杠,则可以使用:
data.df <- iris %>%
data.frame %>%
group_by(Species) %>%
filter(row_number()<=3) %>%
mutate(rowid=1:n()) %>%
ungroup %>%
mutate(Species=as.character(Species)) %>%
mutate(Species=paste0('$\\\\geq$', Species)) %>% # extra backslashes
mutate(rowid=paste0('$\\geq$',rowid)) %>%
rename('$\\geq$rowid'='rowid')
data.df %>%
select(-Species) %>%
kable(., format = 'latex', booktabs=TRUE, escape = FALSE, longtable=TRUE) %>%
group_rows(index = auto_index(data.df$Species), escape = F) %>% # escape = F
kable_styling(latex_options = c('repeat_header','striped','HOLD_position'))