在pdf输出中的kable表中创建水平线

时间:2016-10-18 13:21:12

标签: r knitr r-markdown

我使用rmarkdown创建pdf文档,但无法获得每个块的水平线分隔。代码在

之下
---
title: "Some title"
author: Arvin
date: "October 18, 2016"
output: pdf_document
fig_caption: yes
---


```{r script1, echo = FALSE}
df1 <- data.frame(A1 = c("Sometext", "", "", "B1", "Sometext", ""), 
                  A2 =  c("a", "b", "c", "B2", "d", "e" ),
                  check.names = FALSE)
knitr::kable(df1, caption = "Summary Table")           
```

我试过

```{r script1, echo = FALSE}
df1 <- data.frame(A1 = c("Sometext", "", "", "-------", "B1", "------", "Sometext",  ""), 
                  A2 =  c("a", "b", "c", "-------", "B2", "-------", "d" "e" ),
                  check.names = FALSE)
knitr::kable(df1, caption = "Summary Table")           
```

如何创建分隔每个块的水平线?

1 个答案:

答案 0 :(得分:0)

我建议使用R-package xtable,它在高级功能和表格样式方面非常强大。在你的情况下,我会写:

---
title: "Some title"
author: Arvin
date: "October 18, 2016"
output: pdf_document
fig_caption: yes
---


```{r script1, echo = FALSE, results='asis'}
df1 <- data.frame(A1 = c("Sometext", "", "", "B1", "Sometext", ""), 
                  A2 =  c("a", "b", "c", "B2", "d", "e" ),
                  check.names = FALSE)

print(xtable::xtable(df1), hline.after = c(-1,0,3,6), comment=F)
```