2

以下代码在从 R Studio 编译时生成带有表格的 PDF 文件。有没有办法可以在变量之间插入双竖线(规则)?这将最好使用pander,但我不限于它。

---
output: 
    pdf_document:
        fig_caption: yes
---

```{r}
pander::pander(cars[1:5,], 
               split.cell = 80, 
               split.table = Inf, 
               digits = 4, 
               caption = "Some Caption\\label{tab:sometable}",
               justify = c('right', 'left'))
```

在此处输入图像描述


编辑

我已尝试htmlTable按照以下答案中的建议使用。不幸的是,这不会创建有效的降价代码,以便 knitr 可以创建 PDF,例如

---
output: 
    pdf_document:
        fig_caption: yes
---

```{r}
library('htmlTable')
htmlTable(as.matrix(cars)[1:5, ], caption = 'Table 1: Some caption.',
          css.table = 'border-collapse: collapse; border-style: hidden; border-bottom: 1px;',
          css.cell = 'border-style: none double none none;')
```

产生: 在此处输入图像描述

4

3 回答 3

3

对于 pdf 的 xtable 将是我显示表格的首选:

```{r results="asis",echo=FALSE,message=FALSE}
library(xtable)

print(xtable(as.matrix(cars)[1:5, ],align=c("rr||r"), caption="some caption"), include.rownames=FALSE)

```

产生这个输出: 在此处输入图像描述

有多种选项可用于修改您的表格: https ://cran.r-project.org/web/packages/xtable/xtable.pdf

于 2016-03-15T16:15:35.360 回答
3

你可能想试试 Max Gordon 的htmlTable

他在小插图中的例子:

htmlTable(txtRound(mx, 1), 
          col.columns = c(rep("#E6E6F0", 4),
                          rep("none", ncol(mx) - 4)),
          align="rrrr|r",
          cgroup = cgroup,
          n.cgroup = n.cgroup,
          rgroup = c("First period", 
                     "Second period",
                     "Third period"),
          n.rgroup = rep(5, 3),
                    tfoot = txtMergeLines("&Delta;<sub>int</sub> correspnds to the change since start",
                                "&Delta;<sub>std</sub> corresponds to the change compared to national average"))

创建

线将瑞典与其他地区分开

于 2016-03-15T15:41:18.460 回答
2

+1 为 htmlTable

library('htmlTable')
htmlTable(as.matrix(cars)[1:5, ], caption = 'Table 1: Some caption.',
          css.table = 'border-collapse: collapse; border-style: hidden; border-bottom: 1px;',
          css.cell = 'border-style: none double none none;')

在此处输入图像描述

于 2016-03-15T15:41:03.560 回答