如何在kable()中设置列宽?

时间:2020-09-25 04:07:47

标签: r kable kableextra

我有一个要针对HTML报告显示的数据表。 她是一张假桌子

BelQ= structure(list(Source = "Kalender 2019", `Sourse of Questions` = "The survey instruments were part of a larger survey that included other motivational constructs. The development and validation of these surveys is reported in prior work [18–22,59]. ",     Results = "PCA analysis reveals that for both genders, sense of belonging and identity were not separate from the Expectancy Value Theory constructs. Instead, sense of belonging was closely tied to self-efficacy, which was therefore labeled as “self-efficacy or belonging” component or factor. ", Questions = "Sense of Belonging or Self-efficacy (not separated in a paper):<br>1. Sometimes I worry that I do not belong in this physics class<br>2. I feel like I can be myself in this class<br>3. I am able to help my classmates with physics in the laboratory or in recitation<br>4. I understand concepts I have studied in physics<br>5. If I wanted to, I could be good at physics research<br>6. ",     Reference = "Kalender, Z. Y., Marshman, E., Schunn, C. D., Nokes-Malach, T. J., & Singh, C. (2019). Gendered patterns in the construction of physics identity from motivational factors. Physical Review Physics Education Research, 15(2), [020119](https://journals.aps.org/prper/abstract/10.1103/PhysRevPhysEducRes.15.020119)"), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame"))

当我尝试生成表时,我无法更改列的宽度,并且出现错误UseMethod(“ nodeset_apply”)中的错误:没有适用于“ nodeset_apply”的适用方法应用于类“ NULL”的对象“

BelQ  %>%
  kable(format = "html",escape = FALSE) %>%   kable_styling() %>% 
  scroll_box(width = "100%", height = "500px") %>% 
  kable_styling(full_width = F) %>%
  column_spec(1, width = "18em")

我的代码块有{r results="asis" }

1 个答案:

答案 0 :(得分:0)

不确定为什么,scroll_box应该走到最后,width_min应该被使用

BelQ  %>%
  kable(format = "html",escape = FALSE) %>%   
  kable_styling(full_width = F) %>% 
  column_spec(1, width_min = "18em")%>%
  scroll_box(width = "100%", height = "500px")