2015-06-23 38 views
2

我期待在PDF文档中使用,knitrpander创建表格。除了星号应该是子弹之外,该表格应与下面的表1几乎相同。这是否可能只使用上面列出的R库?如何在使用rmarkdown和pandoc的表格中编写(项目符号)列表

sampletable http://i58.tinypic.com/16jlq13.png

这里是我的代码来生成PDF文件(并因此上表):

--- 
title: "xxx" 
author: "xxx" 
date: "xxx" 
output: 
    word_document: default 
    pdf_document: 
    fig_height: 4 
    fig_width: 10 
    highlight: tango 
geometry: margin=3cm 
--- 

```{r global_options, include=FALSE, echo=FALSE} 
require(knitr) 
opts_chunk$set(fig.width=8, fig.height=4, fig.path='figs/', dpi=500, 
       echo=FALSE, warning=FALSE, message=FALSE, results='hide') 
``` 

```{r pandoc_options, include=FALSE, echo=FALSE} 
require(pander) 
panderOptions('digits', 3) 
panderOptions('round', 3) 
panderOptions('keep.trailing.zeros', TRUE) 
panderOptions('keep.line.breaks', TRUE) 
``` 

```{r concepts, echo=FALSE} 
mytable = data.frame(Concept = c("Decoded", "XXX"), 
        Description = c(" 
            \\\n 
            \\\n * Founded in 2011 
            \\\n * * Offers workshops to take people from zero skills and knowledge in programming through to coding a multi-platform app using HTML, CSS and Javascript in a single day 
            \\\n * * Rave reviews", "XXX"), 
        Website = c("http://decoded.com/uk/","XXX")) 

``` 

``` {r concepts_descriptions, results = 'asis'} 
pandoc.table(mytable, style = "multiline", justify = "left", caption = "Concepts and Descriptions") 
``` 

编辑 @Roman感谢您的 - 但是如果我只是替补,我得到以下不太漂亮的表格(“期间”项目符号,不好格式化)...现在对我来说最重要的是列表附带的格式。谢谢!

samplepic_bullet http://i62.tinypic.com/10sest0.png

+0

从理论上讲,你可以用子弹的字符替换星号(•)。你可以用一个简单的gsub调用 - 'gsub(“\\ *”,“?”,“*一个列表项”)来做到这一点。 –

+0

我的理解是,pandoc使用LaTeX作为媒介格式。你是否尝试用LaTeX项目符号('$ \ bullet $')替换'*'? (对不起,我没有时间检查这是否正常工作。)在[this]中使用'cdot'(http://stackoverflow.com/questions/19406717/is-there-a-way-to-使用结果的R代码在嵌入式乳胶方程在R - markdow)SO问题可能是有用的。 – Jthorpe

回答

5

默认multiline样式表不支持arbitrary block elements inside of the cells,但grid表一样。因此,这是可能的,只要确保:

  • 您使用grid风格
  • 细胞对齐到left
  • 使用硬换行符在列表元素的结束,使keep.line.break

快速演示:

mytable = data.frame(
    Concept  = c("Decoded", "XXX"), 
    Description = c("* Founded in 2011\ \n* Offers workshops to take people from zero skills and knowledge in programming through to coding a multi-platform app using HTML, CSS and Javascript in a single day", "XXX"), 
    Website  = c("http://decoded.com/uk/","XXX")) 

pander::pander(mytable, keep.line.breaks = TRUE, style = 'grid', justify = 'left') 

产生一个很好的通过pandoc席子HTML列表:

<table> 
<colgroup> 
<col width="13%" /> 
<col width="43%" /> 
<col width="30%" /> 
</colgroup> 
<thead> 
<tr class="header"> 
<th align="left">Concept</th> 
<th align="left">Description</th> 
<th align="left">Website</th> 
</tr> 
</thead> 
<tbody> 
<tr class="odd"> 
<td align="left">Decoded</td> 
<td align="left">* Founded in 2011 * Offers workshops to take people from zero skills and knowledge in programming through to coding a multi-platform app using HTML, CSS and Javascript in a single day</td> 
<td align="left">http://decoded.com/uk/</td> 
</tr> 
<tr class="even"> 
<td align="left">XXX</td> 
<td align="left">XXX</td> 
<td align="left">XXX</td> 
</tr> 
</tbody> 
</table> 

但可与PDF以及:

enter image description here

相关问题