在编织为PDF时创建具有双垂直规则的rmarkdown表

时间:2016-03-15 15:07:29

标签: r knitr r-markdown pander

以下代码在从R Studio编译时生成带有表格的PDF文件。有没有办法在变量之间插入双垂直条(规则)?这最好使用--- 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

enter image description here

修改

我已按照以下答案中的建议尝试使用--- 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;') ``` 。不幸的是,这并没有创建有效的降价代码,因此knitr可以创建PDF,例如

select t1.*
    ,case when s1.period is not null then 'Y' else 'N' end as flag_cur
    ,case when s2.period is not null then 'Y' else 'N' end as flag_prev
    ,s1.cutoff_date as cutoff_date_cur ,s1.cutoff_dtkey as cutoff_dtkey_cur 
    ,s2.cutoff_date as cutoff_date_prev ,s2.cutoff_dtkey as cutoff_dtkey_prev 
into #tmp_leads2
from #tmp_leads t1
left join #param s1 on s1.period = '(a) Current' and s1.begin_date <= t1.CreatedDate and t1.CreatedDate < s1.end_date 
left join #param s2 on s2.period = '(b) Previous' and s2.begin_date <= t1.CreatedDate and t1.CreatedDate < s2.end_date 

生产: enter image description here

3 个答案:

答案 0 :(得分: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"))

创建

Lines separate Sweeden from the others

答案 1 :(得分: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)

```

生成此输出: enter image description here

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

答案 2 :(得分:2)

+1 for 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;')

enter image description here

相关问题