I noticed that when I using tab_spanner() before or after setting a custom alignment using cols_align(), there is a slight misalignment with one of the end columns:
In the code below for Example 1, I set leftmost column of Iris to left-align and the remaining columns to right-align. Looks good.
In Examples 2 and 3 however (I get the same result for both), I see that after introducing a tab spanner over the columns, the "Species" column label seems to now be center-align while the column data itself is right-align (as expected).
Am I doing something incorrectly here? How do I use tab_spanner() without messing up my column alignment.
(Example 1)

(Examples 2 and 3)

library(tidyverse)
library(gt)
#Example 1
gt::gt(iris) %>%
gt::cols_align(align = "left", columns = colnames(iris)[1]) %>%
gt::cols_align(align = "right", columns = colnames(iris)[2:ncol(iris)])
#Example 2
gt::gt(iris) %>%
gt::tab_spanner("tab spanner", 1:5, gather = TRUE) %>%
gt::cols_align(align = "left", columns = colnames(iris)[1]) %>%
gt::cols_align(align = "right", columns = colnames(iris)[2:ncol(iris)])
#Example 3
gt::gt(iris) %>%
gt::cols_align(align = "left", columns = colnames(iris)[1]) %>%
gt::cols_align(align = "right", columns = colnames(iris)[2:ncol(iris)]) %>%
gt::tab_spanner("tab spanner", 1:5, gather = TRUE)
I came to report the same 🕺 It seems all headers are centered after tab_spanner().
Yeah. This is an idea I thought might work out well but really isn't great in practice. I'm going to remove that bit of code that forces the column labels to be aligned center.
With that, cols_align() probably needs some options to set the alignment differently for column labels compared to cells below. (Maybe, we might include a rows option to select a portion of the body cells.)
That sounds like a great solution! (Good to see you on the call earlier this week!)
Thanks! And yeah, I'm definitely down for any working group that involves tables. (It's about time!)
(┛ಠ_ಠ)┛彡┻━┻
You're flipping the table world upside down!!
Love that! You'll notice that your use of emoji and ASCII has resulted in this issue being triaged. I even pinned the issue! Conclusion: emojis + other such things work!
Love that! You'll notice that your use of emoji and ASCII has resulted in this issue being triaged. I even pinned the issue! Conclusion: emojis + other such things work!
Hahaha! That emoticon got a lot of mileage when Teresa flipped a table on the real housewives of jersey, and it's finally useful again! 😆
Thanks @rich-iannone !!!
You’re welcome! And may your data never be forcibly aligned to the center again.
Thank you so much! @rich-iannone
Thank you so much! @rich-iannone
You’re welcome and, at the same time, sorry that this was an issue for so long. Anyway, never too late to improve something!