How to format kable table when knit from .rmd to Word (with bookdown)

后端 未结 3 1644
自闭症患者
自闭症患者 2021-01-12 17:06

I have read the bookdown book and still cannot figure this out. I am trying to create a Word report through bookdown. I want to use kableExtra to

相关标签:
3条回答
  • 2021-01-12 17:47

    The huxtable package is available. It includes similar table customization tools as kableExtra. huxtable is designed to output to LaTeX/PDF and HTML (similar to kableExtra). However, huxtable also includes a as_flextable function to convert a huxtable object to a flextable object, which can be output to Word (as noted by David above). After a lot of searching, it seems to me like huxtable is the only available package that can easily output to all of Word, HTML, and PDF with a single package.

    0 讨论(0)
  • 2021-01-12 17:49

    This was not possible but since pandoc V2 is out, you can do it with package flextable (>= 0.4.0)(and pandoc V2). Below the code you should add into a code chunk:

    library(magrittr)
    library(flextable)
    
    tab_1_curr <- structure(list(myRegion = c("a", "b", "c", "BRITISH COLUMBIA"
     ), Current_Perc_1 = c(85.9, 90.8, 89.7, 88.4), Current_Perc_2 = c(88, 
     91, 89, 89.3), curr_change_1_to_2 = c(2.09999999999999, 0.200000000000003, 
     -0.700000000000003, 0.9)), .Names = c("myRegion", "Current_Perc_1", 
     "Current_Perc_2", "curr_change_1_to_2"), row.names = c(NA, 4L
     ), class = "data.frame")
    
    
    regulartable(tab_1_curr) %>% 
      bold(i = ~ myRegion %in% "BRITISH COLUMBIA") %>% 
      theme_zebra() %>% 
      autofit()
    
    0 讨论(0)
  • 2021-01-12 18:00

    Pandoc

    The conversion to word is made via pandoc. Currently pandoc only creates four type of tables,

    • simple tables
    • multiline_tables
    • grid_tables
    • pipe_tables

    Some of those supported formats are demontrated in pander and in the pandoc manual p 35-39.

    So you cannot create the stripped table currently with pandoc.

    You also have a good summary of how you can use tables in rmarkdown.rstudio.

    Pandoc v2

    see the good news from David below

    0 讨论(0)
提交回复
热议问题