0

I have a table in quarto like this:

library(tidyverse)
library(gt)
Variables<-c("x", "y", "z", )
Description<-c("a", "b",  "c")
Expectation<-c("Positive sign", "Negative sign", "Negative sign")
Expectation<-tibble( Variables,
        Description,
        Expectation)

I would like the text to be aligned at the center, my code is:

Expectation %>% gt() %>%
  cols_align(
    align="center",
    columns=everything()
  ) %>% 
  fmt_markdown(columns=everything()) %>% 
  tab_options(table.width = pct(100))%>% 
    tab_style(
    style = list(
      cell_text(align = "center")
    ),
    locations = cells_stub(rows = TRUE)
  )

Nevertheless, the output is aligned to the left. Can someone help me with this? Thanks!

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

Your code should work ({quarto} version: 1.2):

---
format: html
execute: 
  warning: false
  message: false
---


```{r}
library(tidyverse)
library(gt)
Variables <- c("x", "y", "z")
Description <- c("a", "b", "c")
Expectation <- c("Positive sign", "Negative sign", "Negative sign")
Expectation <- tibble(
  Variables,
  Description,
  Expectation
)


Expectation %>%
  gt() %>%
  cols_align(
    align = "center",
    columns = everything()
  ) %>%
  fmt_markdown(columns = everything()) %>%
  tab_options(table.width = pct(100)) %>%
  tab_style(
    style = list(
      cell_text(align = "center")
    ),
    locations = cells_stub(rows = TRUE)
  )
```

example_gt

Julian
  • 6,586
  • 2
  • 9
  • 33