kable,可弹,可huxto html:强制单个线上的单元内容显示
我希望我的单元格中的内容显示在一条线上。我正在将rmarkDown用于HTML。 但是,无论我使用哪个软件包(kable
,flextable
,huxtable
),都忽略了列宽度规范,并介绍了换行符,取得非常丑陋和不可读的结果。 在HTML中,有一个下拉框,总宽度不应该是问题。我只希望结果可读。
library(kableExtra)
library(flextable)
table = as.data.frame(matrix(rep("value [value1 - value2]",20), ncol = 10))
kbl(table) %>%
kable_paper() %>%column_spec(1:ncol(table), width = "3.5cm", bold = TRUE, italic = TRUE)%>%
scroll_box(width = "1000px", height = "500px")
tb = flextable(table)%>% flextable::width(width = 10)
knit_print(tb)
I want the contents of my cells to be displayed in a single line. I'm using Rmarkdown to HTML.
But no matter which package I use (Kable
, Flextable
, Huxtable
), the column width specification is ignored and a line break is introduced, which makes the very ugly and unreadable results.
In HTML, with a drop-down box, the total width shouldn't be a problem. I just want the results to be readable.
library(kableExtra)
library(flextable)
table = as.data.frame(matrix(rep("value [value1 - value2]",20), ncol = 10))
kbl(table) %>%
kable_paper() %>%column_spec(1:ncol(table), width = "3.5cm", bold = TRUE, italic = TRUE)%>%
scroll_box(width = "1000px", height = "500px")
tb = flextable(table)%>% flextable::width(width = 10)
knit_print(tb)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用Flextable,此代码力(请注意
autofit()
的使用情况)在一行上显示显示:这将在HTML窗口中产生表显示,此窗口的宽度有限(窗口的大小或HTML页面的最大宽度)。如果浏览器窗口的宽度小于表的宽度,则将压缩以适合窗口或可用空间。
如果您需要水平滚动(已经用于预订,但还没有用于所有HTML格式),则可以将此CSS代码添加到您的R Markdown中,以便可以滚动(即将集成到Flextable) ):
带有它的html'r markdown'文档:
With flextable, this code forces (note the usage of
autofit()
) the display on one single line:This will produce a table display in an HTML window, this window has a width that is limited (the size of your window or the max-width of your HTML page). If the width of the browser window is less than the width of the table, it will be compressed to fit the window or the available space.
If you need to make this flextable horizontally scrollable (it is already implemented for bookdown but not yet for all HTML format), you can add this CSS code to your r markdown so that flextables can be scrollable (soon integrated into flextable then soon not necessary):
An HTML 'R Markdown' document with it:
这是huxtable等效的:
它使桌子宽尽可能宽:
Here is the huxtable equivalent:
which makes the table as wide as you want: