Controlling column width in Kable when icons are present (html table)

I am trying to produce a table using kableExtra that contains icons in an html document created with Quarto.

If I have only numbers in the table, the following code works fine.

theMatrix <- matrix(data=c(1:12), nrow=3, ncol=4)
theDF <- as.data.frame(theMatrix)
names(theDF) <- c("V1", "V2", "V3","V4")
theTable <- theDF %>%
  kable("html", escape=F) %>%
  column_spec(4, color="blue", background="yellow") %>%
  column_spec(3, color="yellow", background="cyan", width="2em") %>%
  column_spec(2, color="black", background="magenta", width="2em") 

theTable

If there are icons in the columns, the width argument seems to have no effect. I'd like to be able to control the width of both columns with numbers and columns with icons.


theMatrix <- matrix(nrow=3, ncol=4)
theDF <- as.data.frame(theMatrix)
names(theDF) <- c("V1", "V2", "V3","V4")

theDFicons <- theDF %>%
  mutate(V1=fa("circle-half-stroke")) %>%
  mutate(V2=c(1:3)) %>%
  mutate(V3=fa("circle")) %>%
  mutate(V4=fa("envelope"))

theTable <- theDFicons %>%
  kable("html", escape=F) %>%
  column_spec(4, color="blue", background="yellow") %>%
  column_spec(3, color="yellow", background="cyan", width="2em") %>%
  column_spec(2, color="black", background="magenta", width="2em") 
  
theTable

Thanks for any help you can provide.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.