How to write (bullet) lists in a table using rmarkdown and pandoc

前端 未结 1 830
不思量自难忘°
不思量自难忘° 2021-01-13 21:36

I am looking to create a table in a PDF document using rmarkdown, knitr and pander. The table should be nearly identical to Table 1 sh

相关标签:
1条回答
  • 2021-01-13 21:58

    The default multiline style table does not support arbitrary block elements inside of the cells, but the grid tables does. So this is possible, just make sure:

    • you use grid style
    • align the cell to the left
    • use hard line breaks at the end of the list elements and enable keep.line.break

    Quick demo:

    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')
    

    Resulting in a nicely formatted HTML list via pandoc:

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

    But works with PDF as well:

    enter image description here

    0 讨论(0)
提交回复
热议问题