【问题标题】:tables rmarkdown cellpadding表格 rmarkdown 单元格填充
【发布时间】:2017-10-31 07:24:05
【问题描述】:

我正在尝试在 rmarkdown 中使用 hwrite 或 xtable 制作表格以生成 html 表格。我一直无法使用 cellpadding 或 cellspacing 选项,这是我正在使用的代码,附件是输出的照片。

{r, echo = FALSE, results = 'asis'}

cat(hwrite(sd.m.table, row.names = FALSE, cellpadding = 10, row.style = list("font-weight:bold")))

使用 xtable() 也同样无效。有人有建议吗?

Generated output from code

【问题讨论】:

    标签: r r-markdown


    【解决方案1】:

    我不熟悉hwriter 包,并且我很少再使用xtable(因为我对自定义表格感到沮丧),所以我无法就使用这些包给你具体建议。

    我对@9​​87654323@ 最满意(因为它是我写的),但htmlTabletableHTML 包可以生成漂亮的HTML 表格,可能也值得研究。

    pixiedust 的工作示例

    ---
    title: "Untitled"
    output: html_document
    ---
    
    ```{r}
    library(pixiedust)
    
    head(mtcars) %>%
      dust() %>%
      sprinkle(pad = 10) %>%
      medley_all_borders()
    ```
    

    编辑:

    要使用您的数据获得您正在寻找的外观,请尝试使用

    library(pixiedust)
    library(dplyr)
    
    
    DF <- 
      data.frame(rep_complete_time = c("2017-01-04 08:58:22",
                                       "2017-01-04 08:58:33",
                                       "2017-01-06 11:35:28"),
                 result = c(4.99184, 4.07356, 5.01569),
                 body_fluid = c("Serum", "Serum", "Serum"),
                 result_type = c("QC", "QC", "QC"),
                 fluid_lot = c(4426, 4426, 4426),
                 level = c(1, 1, 1))
    
    DF %>%
      # for some reason, sprintf results aren't holding when used in a 
      # sprinkle.  This seems like a bug in pixiedust.
      mutate(result = sprintf("%0.1f", result)) %>%
      dust() %>%
      sprinkle_colnames("Rep Complete Time", "Result", "Body Fluid",
                        "Result Type", "Fluid Lot", "Level") %>%
      # use part = "table" to apply borders to all parts of the table.
      # by default, pixiedust only wants to work with the body of the table.
      medley_all_borders(part = "table") %>%
      # using the sprinkle_table function can apply sprinkles to all of the
      # parts of a table.
      sprinkle_table(pad = 10,
                     halign = "left") 
    

    我无法复制您的对齐问题。我的结果中的所有列都左对齐。

    【讨论】:

    • 这是一个非常有用的软件包,我以前从未听说过!我现在遇到的唯一问题是,即使使用sprinkle(halign = "left"),也不是所有列都像我想要的那样左对齐,我无法在标题周围设置边框,并且当一列四舍五入到 0.1 并且值是一个整体数字显示为 5 而不是 5.0
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2015-06-04
    相关资源
    最近更新 更多