表rmarkdown cellpadding

时间:2017-05-30 17:45:12

标签: r r-markdown

我正在尝试使用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

1 个答案:

答案 0 :(得分:0)

我不熟悉hwriter包,我很少再使用xtable(因为我对自定义表感到沮丧),所以我不能给你具体的建议。

我对pixiedust感到最舒服(因为我写了它),但是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") 

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