R 调整pandoc.table列宽

R 调整pandoc.table列宽,r,knitr,pandoc,r-markdown,pander,R,Knitr,Pandoc,R Markdown,Pander,下面的文档提供了以下HTML输出(仅需要HTML) 第一列非常宽,在这里没有帮助 如何强制前两列减少浪费空间 --- 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 a

下面的文档提供了以下HTML输出(仅需要HTML)

第一列非常宽,在这里没有帮助

如何强制前两列减少浪费空间

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

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              
----------------------------------------------------------------------
在使用
pandoc
将上述标记转换为HTML后,将生成以下HTML:

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

可乐
可乐
可乐
1.
2001
这是一个漫长的测试,应该反复反复反复
2.
2002
这是一个漫长的测试,应该反复反复反复

谢谢。我应该仔细阅读:split.cells“也可以作为向量提供”此解决方案导致第三列从第一列和第二列捕获空间,但实际上并不直接处理单元格宽度。假设您有更多的列,结果pander正在拆分表。此解决方案不允许您在包装长文本列的同时压缩具有额外空间的列,以使所有列位于同一行。