[英]Kable column width in html rmarkdown
I want to display a wide kable
table in html rmarkdown to display the first column has long text without any line breaks.我想在 html rmarkdown 中显示一个宽的
kable
表,以显示第一列有没有任何换行符的长文本。 When I set the first column's width using column_spec
, it doesn't seem to have any effect on the resulting html table.当我使用
column_spec
设置第一列的宽度时,它似乎对生成的 html 表没有任何影响。 Here's my code.这是我的代码。 Is there a way to not have any line breaks for the first column?
有没有办法让第一列没有任何换行符? Thanks!
谢谢!
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
You'll need to set width_min
in column_spec
.您需要在
column_spec
中设置width_min
。 I think 3in
is already enough for your column 1 in the example.我认为
3in
对于示例中的第 1 列已经足够了。
If you really need 10in
for some reason, you can add scroll_box()
to enable x-axis scrolling in the table (not included in my answer).如果出于某种原因你真的需要
10in
,你可以添加scroll_box()
来启用表格中的 x 轴滚动(不包括在我的回答中)。
kable(df, col.names = colnames(df), escape = F) %>%
kable_styling(full_width = T) %>%
column_spec(1, width_min = '3in')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.