gpt4 book ai didi

r - 调整pandoc.table列宽

转载 作者:行者123 更新时间:2023-12-03 20:26:09 25 4
gpt4 key购买 nike

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

前几列是扩展的方法,Reduce cell width and font size of table using pandoc.table()在这里无济于事。

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

---
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参数支持specifying the width of columns,它可以采用简单数字或(相对)数字/百分比的向量,快速演示:

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

将上面的markdown转换为带有 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>

关于r - 调整pandoc.table列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971785/

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