Search code examples
rgt

Right align the rowname_col in gt


I'd like to right align the rowname_col but it doesn't look like you can apply cols_align to rownames?

tibble(
  one = c("Long names", "Other Name", "Name | Name"),
  two = 1:3
) %>% gt(rowname_col = "one") %>%
  cols_align(align = "right", columns = vars(one))

enter image description here


Solution

  • You can right align the rowname column like so:

    library(dplyr)
    library(gt)
    
    tibble(
      one = c("Long names", "Other Name", "Name | Name"),
      two = 1:3
    ) %>% gt(rowname_col = "one") %>%
      tab_style(
        style = list(
          cell_text(align = "right")
        ),
        locations = cells_stub(rows = TRUE)
      )
    

    enter image description here