使用pandoc.table()减少表格的单元格宽度和字体大小 [英] Reduce cell width and font size of table using pandoc.table()

查看:243
本文介绍了使用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

这篇关于使用pandoc.table()减少表格的单元格宽度和字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆