GT table colours don't appear in PDF dcoument

I'm trying to add a table that has colour coded columns using the gt package. It works in the console:

but doesn't work when the pdf is created:

My full markdown is:

---
title: "Untitled"
output: pdf_document
---

```{r setup}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(gt)
```

## GT package

```{r table1, results='asis'}
starwars %>% 
  select (name, height, mass, hair_color, skin_color, sex, gender) %>% 
  head (5) %>% 
  gt() %>% 
   tab_style(
    style = list(
      cell_fill(color = "lightcyan"),
      cell_text(weight = "bold")
      ),
    locations = cells_body(
      columns = vars(height),
      rows = height > 150)
  ) 
  
```

Hi greg, I have the same issue. Did you manage to solve it?

You might need to use some LaTeX packages in the header.

See example here: https://stackoverflow.com/questions/45311909/how-do-you-color-the-cell-in-rmarkdown-pdf-output

I never did manage to find a solution using gt but it can be done using flextable.

starwars %>% 
  select (name, height, mass, hair_color, skin_color, sex, gender) %>% 
  head (5) %>% 
  flextable () %>% 
  color (~ height > 150, ~ height, color = "cyan")
2 Likes