我有一个带有yaml部分的rmarkDown文件:

问题描述 投票:0回答:1

I有一个块,可以使用第1列中的崩溃行与kablextra格式化长桌子。在将数据框架设置为

kbl()
i有条件的颜色之前,列3:5。问题是边界在条件格式化的单元格中不显示(实际和水平的)。  我如何在不破坏构建的情况下展示边界?我尝试了
booktabs =TRUE

,但这在行线之间创建了空的空白,也可以在第3:5列中的值合理而不是顶部。

{r, warning = FALSE ,message=FALSE,fig.width=9, fig.height=9, dpi= 1200} format_column <- function(x) { case_when( x < 1.5 ~ cell_spec(x, background = "#ed2e1c", color = "black",format = "latex" ), # [1–1.5[ x >= 1.5 & x <= 2.5 ~ cell_spec(x, background = "#e09c95", color = "black",format = "latex"), # [1.5–2.5] x > 2.5 & x < 3.5 ~ cell_spec(x, background = "#85c1e9", color = "black", format = "latex"), # ]2.5–3.5[ x >= 3.5 & x <= 4.5 ~ cell_spec(x, background = "#7FF98B", color = "black", format = "latex"), # [3.5–4.5] x > 4.5 & x <= 5 ~ cell_spec(x, background = "#04B431", color = "black", format = "latex"), # ]4.5–5] TRUE ~ cell_spec(x, background = "white" , color = "black", format = "latex") # Default ) }
{r, warning = FALSE ,message=FALSE,fig.width=9, fig.height=9, dpi= 1200,results='asis'}
 df_formatted = DF %>%
    mutate(across(c(3:5), format_column))
  
  df2 =  df_formatted %>%
    kable(align = "llccc", format = "latex", escape = FALSE) %>%
    kable_styling(font_size = 7, bootstrap_options = c("bordered"), latex_options = "HOLD_position") %>%
    column_spec(1, width = "2cm", border_left = TRUE) %>%
    column_spec(2, width = "12cm") %>%
    column_spec(3:4, width = "1.5cm") %>%
    column_spec(5, width = "1.5cm", border_right = TRUE) %>%
    collapse_rows(columns = 1, valign = "middle") %>%
    row_spec(0, background = "#D3D3D3", bold = TRUE)
  

  
  print(df2)

如何使用kablextra在r中实现这一目标?
data

DF = structure(list(category = c("Capability", "Capability", "Capability", 
                                 "Capability", "Capability", "Capability", "Capability", "Capability", 
                                 "Capability", "Capability", "Capability", "Capability", "Capability", 
                                 "Capability", "Challenge", "Challenge", "Challenge", "Challenge", 
                                 "Contracting Management Topics", "Contracting Management Topics", 
                                 "Contracting Management Topics", "Contracting Management Topics", 
                                 "Contracting Management Topics", "Contracting Management Topics", 
                                 "Contracting Management Topics", "Cooperation Site Supervision", 
                                 "Cooperation Site Supervision", "Cooperation Site Supervision", 
                                 "Cooperation Site Supervision", "Cooperation Site Supervision", 
                                 "Cooperation Site Supervision", "Cooperation Site Supervision", 
                                 "Core Beliefs", "Core Beliefs", "Expense", "Safety", "Safety", 
                                 "Safety", "Safety", "Safety", "Safety", "Excellence", "Excellence", 
                                 "Excellence"), questions = c("Do you believe that the following attributes define XYZ? Dedicated", 
                                                              "Do you believe that the following attributes define XYZ? Credible", 
                                                              "Do you believe that the following attributes define XYZ? Creative", 
                                                              "Do you believe that the following attributes define XYZ? Sincere", 
                                                              "Do you believe that the following attributes define XYZ? Ambitious", 
                                                              "Do you believe that the following attributes define XYZ? Qualified", 
                                                              "Do you believe that the following attributes define XYZ? Honest", 
                                                              "Extensive Building knowledge", "The capacity to rapidly share data on your projects", 
                                                              "The skill to coordinate your projects", "Skilled and talented personnel", 
                                                              "A variety of building services that can be adjusted to fit your demands", 
                                                              "Do you believe that the following attributes define XYZ? Dedicated", 
                                                              "Do you believe that the following attributes define XYZ? Credible", 
                                                              "Please evaluate your contentment regarding the following: Compared to competitors, how pleased are you with XYZ?", 
                                                              "Kindly respond to the following inquiries: How inclined are you to use our solutions again?", 
                                                              "Kindly respond to the following inquiries: Would you refer XYZ to associates?", 
                                                              "Please evaluate your contentment regarding the following: Compared to competitors, how pleased are you with XYZ?", 
                                                              "How pleased are you with the pace at which XYZ handled your concerns and grievances?", 
                                                              "The final resolution of your concerns and grievances", "Please evaluate your contentment regarding the following: Billing", 
                                                              "Please evaluate your contentment regarding the following: Requests", 
                                                              "Please evaluate your contentment regarding the following: Adherence to your needs", 
                                                              "Please evaluate your contentment regarding the following: Prompt reaction to your needs", 
                                                              "Please evaluate your contentment regarding the following: Compliance with the plan", 
                                                              "How pleased are you with XYZ executives’ accessibility?", "How pleased are you with XYZ’s efficiency in field monitoring?", 
                                                              "How pleased are you with XYZ’s capacity to accomplish tasks as requested?", 
                                                              "How pleased are you with team expertise and comprehension of building techniques?", 
                                                              "How pleased are you with issue resolution (Provide corresponding examples)?", 
                                                              "How pleased are you with cooperation with client teams?", 
                                                              "How pleased are you with XYZ executives’ accessibility?", "XYZ is devoted to offering exceptional quality service; how pleased are you with our outputs?", 
                                                              "How pleased are you with XYZ policies concerning Security, Protection, and Well-being?", 
                                                              "Please evaluate your contentment regarding the following: The entire expenditure of the undertaking (Original proposal & requests)", 
                                                              "How pleased are you with XYZ policies concerning Security, Protection, and Well-being?", 
                                                              "XYZ Security Framework on the Project", "XYZ’s accountability and dedication to Security on the Project", 
                                                              "Proficiency of XYZ Project Security Team", "Clarity, efficiency, and openness of reports linked to incident assessments", 
                                                              "Dialogue between XYZ project executives and yours concerning Security", 
                                                              "XYZ’s accountability and dedication to Excellence on the project", 
                                                              "XYZ’s Excellence Administration Framework execution on the project", 
                                                              "Productivity, proficiency, and openness concerning remedial steps on quality aspects"
                                 ), `House ball Score (/5)` = c(3, 3, 3, 2, 3, 4, 3, 3, 3, 
                                                                     2, 2, 3, 2, 2, 3, 3, 3, 2, 3, 3, 3, 3, 2, 2, 1, 3, 2, 2, 3, 2, 
                                                                     2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), `House toy Score (/5)` = c(2L, 
                                                                                                                                                3L, 3L, 1L, 5L, 2L, 3L, 3L, 2L, 5L, 4L, 1L, 4L, 5L, 1L, 2L, 3L, 
                                                                                                                                                5L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 1L, 3L, 2L, 2L, 1L, 1L, 3L, 4L, 
                                                                                                                                                5L, 4L, 5L, 3L, 4L, 4L, 4L, 2L, 3L, 5L, 5L), `House Car Score (/5)` = c(4L, 
                                                                                                                                                                                                                         1L, 1L, 2L, 5L, 2L, 1L, 3L, 3L, 4L, 3L, 4L, 4L, 1L, 1L, 5L, 4L, 
                                                                                                                                                                                                                         1L, 1L, 4L, 5L, 4L, 4L, 2L, 5L, 2L, 1L, 3L, 5L, 4L, 2L, 3L, 4L, 
                                                                                                                                                                                                                         2L, 2L, 1L, 3L, 1L, 4L, 2L, 5L, 3L, 3L, 3L)), row.names = c(NA, 
                                                                                                                                                                                                                                                                                     -44L), class = c("tbl_df", "tbl", "data.frame"))

I使用
hhline
软件包找到了一个解决方案

cline enter image description heregiving

r dplyr latex kableextra
1个回答
0
投票

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.