首页 > 解决方案 > 在输出中保持 DT 表的行高相同

问题描述

我想为 DT 表输出设置行常量或固定的高度。对于下表,您可以看到行高的差异。

所以这种情况是当字符数量增加时,例如在这种情况下,在第一个列中的第二行,那么所有行的高度都应该调整为相同。

df <- data.frame(`quote` = c("the trader belongs to","trader have long ralationship withthe same market with my opinion on thaw its implemented mmnnhhh sdfghj fghj kjhgf tyui cvbnm",
                             "types of trads happens everytime when market slow","trades have leverage with",
                             "market is continious with the same platform trades"),
                 `share`= c(43,65,92,23,73),
                 `times` = c(86,98,55,12,08),
                 `parts`=c(4,7,4,8,3))


df<-datatable(df,
              options = list(columnDefs = 
                               list(list(className = 'dt-center', 
                                         targets = "_all"))),rownames = FALSE)
df

就像在 flextable 中一样,我可以执行以下操作,但要为 DT 表寻找固定解决方案或任何功能。

(ncols %in% c(4,5)) {
    fl<-width(flxtable, width = d*0.3, j = 1)
    fl<-width(flxtable, width = (d*0.7)/(ncols-1), j = 2:ncols)
d is left and right margin of docs template

标签: rdt

解决方案


我过去在这方面取得了成功:

DT::datatable(df) %>%
DT::formatStyle(names(df),lineHeight='80%') 

感谢帮助我的帖子,但是我现在找不到它了。


推荐阅读