gpt4 book ai didi

r - 如何使用 rmarkdown 和 pandoc 在表格中编写(项目符号)列表

转载 作者:行者123 更新时间:2023-12-01 09:54:33 25 4
gpt4 key购买 nike

我希望使用 rmarkdown 在 PDF 文档中创建表格, knitrpander .该表应该与下面显示的表 1 几乎相同,只是星号应该是项目符号。仅使用 R 就可以做到这一点吗?上面列出的库?
sampletable

这是我生成 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

最佳答案

默认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

    关于r - 如何使用 rmarkdown 和 pandoc 在表格中编写(项目符号)列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31011265/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com