6

以下文档给出了以下 HTML 输出(仅需要 HTML)

pandoc的列宽

第一列是宽的,使用 pandoc.table() 减少表格的单元格宽度和字体大小在这里没有帮助。

如何强制前 2 列浪费更少的空间?

---
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)
```
4

1 回答 1

12

pandoc.table支持通过参数指定列的宽度split.cells,可以采用简单的数字或(相对)数字/百分比的向量,快速演示:

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

在将上述降价转换为 HTML 后,这会产生以下 HTML 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>
于 2014-11-17T14:38:54.070 回答