gt table alignment in tufte

I am including gt tables in a Tufte-style HTML. I want to align the gt tables left so that they are in the main column, rather than down the center of the HTML spanning both the main column and margin. I have tried using the fig.align knitr option but it is not working. Here is the r code chunk for the gt table, as well as the tufte formatting I am using.


title: "Rubin Causal Model"
output:
tufte::tufte_html:
tufte_variant: "envisioned"

tufte::tufte_handout: default


library(tufte)
library(gt)
library(tidyverse)

# First, we create a tibble with the values we want for the table

tibble(subject = "Joe",
       ytreat = "13",
       ycontrol = "9",
       ydiff = "+4") %>%
  
  # Then, we use the gt function to make it pretty
  
  gt() %>%
  cols_label(subject = md("**Subject**"),
                ytreat = "Attitude if Treated",
                ycontrol = "Attitude if Control",
                ydiff = "Treatment Effect") %>%
  tab_style(cell_borders(sides = "right"),
            location = cells_body(columns = vars(subject))) %>%
  tab_style(cell_text(weight = "bold"),
            location = cells_body(columns = vars(subject))) %>%
  cols_align(align = "center", columns = TRUE)

Do you get what you want when you add

%>%
  tab_options(table.align='left')

?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

That puts the table all the way on the left of the html, rather than centered in the main column.