我希望在html rmarkdown中显示一个宽的kable
表,以显示第一列有长文本,没有任何换行。当我使用column_spec
设置第一列的宽度时,它似乎对生成的html表没有任何影响。这是我的密码。是否有一种方法可以不对第一列进行任何换行符?谢谢!
df <- data.frame(v1 = c('Long text without line breaks', 'Long text without line breaks', 'Long text without line breaks'),
v2 = c('text', 'text', 'text'),
v3 = c('text', 'text', 'text'),
v4 = c('text', 'text', 'text'),
v5 = c('text', 'text', 'text'),
v6 = c('text', 'text', 'text'),
v7 = c('text', 'text', 'text'),
v8 = c('text', 'text', 'text'),
v9 = c('text', 'text', 'text'),
v10 = c('text', 'text', 'text'),
v11 = c('text', 'text', 'text'),
v12 = c('text', 'text', 'text'),
v13 = c('text', 'text', 'text'),
v14 = c('text', 'text', 'text'),
v15 = c('text', 'text', 'text'),
v16 = c('text', 'text', 'text'),
v17 = c('text', 'text', 'text'),
v18 = c('text', 'text', 'text'),
v19 = c('text', 'text', 'text')
)
gctbl <- kable(df, col.names = colnames(df), escape = F) %>%
kable_styling(full_width = T) %>%
column_spec(1, width = '10in')
gctbl
发布于 2022-02-10 08:50:35
您需要在width_min
中设置column_spec
。我认为3in
已经足够用于本例中的第1列了。
如果您出于某种原因确实需要10in
,可以添加scroll_box()
以启用表中的x轴滚动(不包括在我的回答中)。
kable(df, col.names = colnames(df), escape = F) %>%
kable_styling(full_width = T) %>%
column_spec(1, width_min = '3in')
https://stackoverflow.com/questions/71061991
复制相似问题