Reputation: 1549
I need to write the greater or equal than math symbol on two of my column headers and printing a gridExtra table but can't make it work. Below is small Rmarkdown document showing what I am trying to do. I am still using gridExtra 0.9.1 because all of my tables work nicely with this version.
---
title: "Math symbols in column headers"
date: "January 15, 2020"
output: pdf_document
---
```{r}
library(gridExtra)
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("Estimated abundance of\n White Sharks\n $\\\\geq$ 40 inches in total length","Percentage of 3 year old\n White shark in the population\n $\\\\geq{40}$ inches in total length")
grid.table(a)
```
I have tried different variations but I can't get it right. Can someone point me on the right direction? I also tried using kableExtra with no luck. This is what I get, notice my column headers:
Upvotes: 1
Views: 590
Reputation: 6234
Add a theme with ttheme_default(colhead=list(fg_params = list(parse=TRUE)))
to use plotmath notation in the column headers.
---
title: "Math symbols in column headers"
date: "January 15, 2020"
output: pdf_document
---
```{r, echo = FALSE}
library(gridExtra)
a <- data.frame(
MLE = c(0.0839, 0.2082, 0.4194, 0.8237, 1.6201),
MME = c(0.0839, 0.2082, 0.4194, 0.8234, 1.6147)
)
colnames(a) <- c(bquote(atop("Estimated abundance of White Sharks", "" >= 40 ~ "inches in total length")),
bquote(atop("Percentage of 3 year old White Sharks", "" >= 40 ~ "inches in total length")))
tt <- ttheme_default(colhead=list(fg_params = list(parse=TRUE)))
grid.table(a, theme=tt)
```
Note: the line breaks are now specified by atop
, since bquote
does not interpret \n
linebreaks
Upvotes: 1