2014-11-17 2 views
4

В приведенной ниже документ дает следующий вывод HTML (требуется только HTML)Адаптировать pandoc.table ширина колонки

column widths with pandoc

Первые столбцы путь к широкому и Reduce cell width and font size of table using 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) 
``` 

ответ

8

pandoc.table поддерживает specifying the width of columns через 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> 
+0

Thanks. Я должен был бы более внимательно прочитать: split.cells «Может также поставляться как вектор» –

Смежные вопросы