[英]Unable to Left align table columns using KableExtra
I've a table which I'm trying to visualize using KableExtra and formattable package.我有一个表格,我正在尝试使用 KableExtra 和 formattable 包对其进行可视化。 The problem I'm facing is that despite specifying the alignment of the columns to be left, some of the columns are not being left aligned.我面临的问题是,尽管指定了要左对齐的列,但某些列并未左对齐。 See screenshot here:在此处查看屏幕截图:
Here's the codeI'm using:这是我正在使用的代码:
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)
What am I missing here ?我在这里错过了什么?
This issue only occurred when I was viewing the results in Rstudio.仅当我在 Rstudio 中查看结果时才会出现此问题。 IT worked perfectly fine when exported as an HTML.当导出为 HTML 时,它工作得非常好。 So there was no issue to be addressed here.所以这里没有问题需要解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.