使用pandoc.table()减少表格的单元格宽度和字体大小

问题描述:

我正在使用knitrpander在markdown文件中创建表格.我正在使用R中的Pandoc将markdown文件转换为PDF.

I'm using knitr and pander to make a table in a markdown file. I'm converting the markdown file to a PDF using Pandoc from within R.

此代码:

library(knitr)

```{r myTable, echo=FALSE, message=FALSE, results='asis', comment=""}

library(pander)
pandoc.table(head(iris))

``` 

然后在R中运行此功能:

then running this function within R:

knitsPDF <- function(name) {
  knit(paste0(name, ".Rmd"), encoding = "utf-8")
  callformat <-"pandoc -V geometry:margin=1in  %s.md -o %s.pdf"
  system(sprintf(callformat, name, name))
}

knitsPDF(name) # insert file name of .Rmd file

在PDF文件中生成此表:

produces this table in the PDF file:

如何1.减少表格中的列宽度? 2.减小表格的字体大小吗?

How can I 1. Reduce width of columns in table? 2. Reduce font size of table?

如果您不想根据表格的宽度将表格分为多个部分,则可以直接在split.tables参数中使用pandoc.table或更大的值进行指定通常在panderOptions中的table.split.table中.例如:

If you do not want to split the table into multiple parts based on its width, you can specify that directly in split.tables parameter with pandoc.table or more generally in table.split.table in panderOptions. E.g.:

> pandoc.table(head(iris), split.table = Inf)

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
     5.1            3.5           1.4            0.2       setosa  

     4.9             3            1.4            0.2       setosa  

     4.7            3.2           1.3            0.2       setosa  

     4.6            3.1           1.5            0.2       setosa  

      5             3.6           1.4            0.2       setosa  

     5.4            3.9           1.7            0.4       setosa  
-------------------------------------------------------------------

> panderOptions('table.split.table', 300)
> pander(head(iris))

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
     5.1            3.5           1.4            0.2       setosa  

     4.9             3            1.4            0.2       setosa  

     4.7            3.2           1.3            0.2       setosa  

     4.6            3.1           1.5            0.2       setosa  

      5             3.6           1.4            0.2       setosa  

     5.4            3.9           1.7            0.4       setosa  
-------------------------------------------------------------------

关于字体大小:Pandoc的markdown对此没有任何特殊语法,因此您可以为pdf使用LaTeX标记.例如.只需在表之前发出\footnotesize指令即可.有关更多详细信息,请参见可能的字体大小: http://en.wikibooks.org/wiki/LaTeX/Fonts#Sizing_text

About fontsize: Pandoc's markdown do not have any special syntax for that, so you might use LaTeX markup for your pdf. E.g. just issue a \footnotesize directive before your table. See possible font sizes for more details: http://en.wikibooks.org/wiki/LaTeX/Fonts#Sizing_text