无法使用 KableExtra 左对齐 table 列
Unable to Left align table columns using KableExtra
我有一个 table,我正在尝试使用 KableExtra 和格式 table 包对其进行可视化。我面临的问题是,尽管指定了要左对齐的列,但某些列并未左对齐。请在此处查看屏幕截图:
这是我正在使用的代码:
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 时,IT 工作得非常好。所以这里没有要解决的问题。
我有一个 table,我正在尝试使用 KableExtra 和格式 table 包对其进行可视化。我面临的问题是,尽管指定了要左对齐的列,但某些列并未左对齐。请在此处查看屏幕截图:
这是我正在使用的代码:
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 时,IT 工作得非常好。所以这里没有要解决的问题。