[英]Unable to Left align table columns using KableExtra
我有一個表格,我正在嘗試使用 KableExtra 和 formattable 包對其進行可視化。 我面臨的問題是,盡管指定了要左對齊的列,但某些列並未左對齊。 在此處查看屏幕截圖:
這是我正在使用的代碼:
df%>%
mutate(
N = comma(N, digits = 0),
`Strongly agree`=color_bar("#D8E2F1")(percent(`Strongly agree`,1)),
`Agree`=color_bar("#D8E2F1")(percent(Agree,1)),
`Neither agree nor disagree`=color_bar("#D8E2F1")(percent(`Neither agree nor disagree`,1)),
`Disagree`=color_bar("#D8E2F1")(percent(Disagree,1)),
`Strongly disagree`=color_bar("#D8E2F1")(percent(`Strongly disagree`,1))
)%>% filter(N!=0) %>%
kable(escape = F, format = "html",align='cclllll', booktabs=T) %>%
kable_styling(c("hover","condensed"), full_width = T) %>%
column_spec(1, bold=T,color="black",border_right = TRUE)%>%
column_spec(2, bold=F,border_right = TRUE,color="black",italic=TRUE)%>%
column_spec(c(3,4,5,6,7),color="black", border_right = TRUE,width = "2in")%>%
row_spec(c(0), extra_css = "border-bottom: 1px solid")%>%
row_spec(c(5,10,15,16,17), bold=TRUE,background="#F3F2F2")%>%
pack_rows("Overall", 1, 5)%>%
pack_rows("Gender: Male", 6, 10)%>%
pack_rows("Gender: Female", 11, 15)%>%
pack_rows("Age 40+", 16, 16)%>%
pack_rows("Age < 40", 17, 17)
我在這里錯過了什么?
僅當我在 Rstudio 中查看結果時才會出現此問題。 當導出為 HTML 時,它工作得非常好。 所以這里沒有問題需要解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.