如您所见,cell_spec
如果您想为整行或整列着色,该函数很有用。由于kableExtra
不提供直接编辑单个单元格的功能,因此“最简单”的方法是将 LaTeX 命令直接粘贴到单元格中。我在这里的类似答案中使用了这种方法:
---
output: pdf_document
header-includes:
- \usepackage{booktabs}
---
```{r pressure, echo=FALSE}
df <- mtcars[1:10, 1:5]
df[1,5] <- paste0("\\underline{", df[1,5], "}")
df[1,1] <- paste0("\\textcolor{red}{", df[1,1], "}")
df[2,2] <- paste0("\\textcolor{green}{\\textbf{", df[2,2], "}}")
# # Equivalent to:
# library(kableExtra)
# df[1, 5] <- cell_spec(df[1, 5], "latex", underline = T)
# df[1, 1] <- cell_spec(df[1, 1], "latex", color = "red")
# df[2, 2] <- cell_spec(df[2, 2], "latex", color = "green", bold = T)
knitr::kable(df, format="latex", booktabs = T, escape = F)
```
您可以调整它以适用于您的示例。您可能想在此处查看可用的 LaTeX 格式:https ://www.sharelatex.com/learn/Bold,_italics_and_underlining