更改R DataTables(DT)中的字体大小 [英] changing font size in R DataTables (DT)
问题描述
一直在尝试更改DT生成的表中所有文本的字体大小。但是,我只能弄清楚如何使用
formatStyle(names(datCalc),fontSize ='12px')
来更改记录的大小。
列标题和按钮的文本大小相同。
Have been trying to change the font size of all text in the tables generated by DT. However, I could only figure out how to change the size of the records using
formatStyle(names(datCalc), fontSize = '12px')
.
The column headers and buttons have text of the same size. Using R Markdown in RStudio.
推荐答案
我认为您快到了。我通过明确告诉 DT :: formatStyle()
来解决此问题。我首先尝试像您一样使用 names()
或 colnames()
方法。出于某些原因,这不起作用:
I think you almost got there. I solved it by explicitly telling DT::formatStyle()
which columns I wanted. I first tried using the names()
or colnames()
approach, as you did. For some reason this didn't work:
iris %>%
DT::datatable() %>%
DT::formatStyle(columns = colnames(.), fontSize = '50%')
但是,我们知道 iris
数据集有5列,所以我只是这样做:
However, we know the iris
dataset has 5 columns, so I just did this:
iris %>%
DT::datatable() %>%
DT::formatStyle(columns = c(1, 2, 3, 4, 5), fontSize = '50%')
在这种情况下,我使用 font -size = 50%
,但是您也可以像指定操作一样指定 font-size = 12pt
。您还可以向列
参数提供 c(T,F,F,F,T)
之类的逻辑矢量,并且格式将应用于您声明为 TRUE
的那些列。
In this case, I use font-size = 50%
, but you can also specify font-size = 12pt
as you did. You can also supply logical vectors like c(T, F, F, F, T)
to the columns
argument, and the formatting will apply to those columns for which you have stated TRUE
.
这篇关于更改R DataTables(DT)中的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!