Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adapt pandoc.table column width

The below document gives the following HTML output (only HTML required)

column widths with pandoc

The first columns are way to wide, and Reduce cell width and font size of table using pandoc.table() does not help here.

How can I force the first 2 columns to waste less space?

---
output: html_document
---

```{r,echo=FALSE, results="asis"}
library(pander)
mytab = data.frame(col1=1:2, col2=2001:2002, col3="This is a lengthy test that should wrap, and wrap again, and again and again and again")
pandoc.table(mytab)
```
like image 357
Dieter Menne Avatar asked Nov 17 '14 11:11

Dieter Menne


1 Answers

pandoc.table supports specifying the width of columns via the split.cells argument, which can take a simple number or a vector of (relative) numbers/percentages, Quick demo:

> pandoc.table(mytab, split.cells = c(1,1,58))

----------------------------------------------------------------------
 col1   col2                            col3                          
------ ------ --------------------------------------------------------
  1     2001  This is a lengthy test that should wrap, and wrap again,
                           and again and again and again              

  2     2002  This is a lengthy test that should wrap, and wrap again,
                           and again and again and again              
----------------------------------------------------------------------

This results in the following HTML after converting the above markdown to HTML with pandoc:

<table>
<col width="9%" />
<col width="9%" />
<col width="77%" />
<thead>
<tr class="header">
<th align="center">col1</th>
<th align="center">col2</th>
<th align="center">col3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="center">2001</td>
<td align="center">This is a lengthy test that should wrap, and wrap again, and again and again and again</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="center">2002</td>
<td align="center">This is a lengthy test that should wrap, and wrap again, and again and again and again</td>
</tr>
</tbody>
</table>
like image 67
daroczig Avatar answered Sep 18 '22 21:09

daroczig