如何使用rmarkdown和pandoc在表中编写多级(项目符号)列表

时间:2015-06-25 11:56:08

标签: r r-markdown pandoc pander

我希望使用rmarkdownknitrpander在PDF文档中创建一个表格。我可以创建一个simple bullet list但现在需要该列表中的另一个级别。在下面的表格中,我要求“Rave reviews”子弹作为“优惠研讨会......”子弹的子弹。

multibullet http://i59.tinypic.com/jtmk43.png

我遇到的问题与mytableDescription数据框中的以下代码行有关。虽然我尝试使用\x20 [1]创建子弹所需的4个空格,但这些空格不会出现 - 因此没有子弹(尽管没有显示错误)。我也尝试过最简单的方法,只需在代码中添加4个空格即可。我还尝试将R选项设置为包含strip.white = FALSE,但这也没有证明有用(见下文)。

---
title: "xxx"
author: "xxx"
output:
  pdf_document:
    fig_height: 4
    fig_width: 10
    highlight: tango
  word_document: default
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', strip.white = FALSE)
```

```{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("* 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\x20\x20\x20\x20+ Rave reviews", "XXX"),
    Website     = c("http://decoded.com/uk/","XXX"))
```

``` {r concepts_descriptions, results = 'asis'}
pander::pander(mytable, keep.line.breaks = TRUE, style = 'grid', justify = 'left')
```

参考

[1]在尝试\x20\\s\s\ \s等后,我从here获得\\\s提示。无济于事(建议here)。

2 个答案:

答案 0 :(得分:2)

您可以将项目嵌套在项目符号中:

var activeObject:ActiveObject!

答案 1 :(得分:2)

编辑:我没有意识到你使用的是pdf,但这是一个HTML解决方案

  1. 我会使用矩阵
  2. 我会使用htmlTable包,它允许比kable或pander更高级的表
  3. 首先为列表创建一个包装器

    make_list <- function(...) {
      paste0("<ul>", sprintf('<li>%s</li>', substitute(...())), '</ul>', collapse = '')
    }
    
    make_list(one, two, three)
    
    # [1] "<ul><li>one</li></ul><ul><li>two</li></ul><ul><li>three</li></ul>"
    
    
    library('htmlTable')
    mytable <- matrix(c("Decoded", "XXX",
                        make_list('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','Rave reviews'),
                        "XXX",
                        "http://decoded.com/uk/","XXX"), 2,
                      dimnames = list(NULL, c('Concept','Description','Website')))
    
    htmlTable(mytable, align = 'lll')
    

    enter image description here

    这很好,但垂直对齐很差,盒子太宽。但我们可以使用htmlTable的css参数之一进行修复。 vertical align将文本推到顶部而不是中心,max-width设置文本换行,自动宽度让每个都有自己的宽度

    htmlTable(mytable, align = 'lll', align.header = 'lll',
              css.cell = "width: auto; max-width: 250px; vertical-align: top;")
    

    enter image description here