2017-03-22 51 views
1

我在我的Rmarkdown文檔中使用pander來顯示錶格。有沒有在桌子的中心?居中放大表

我已經嘗試了幾種不同的方法,但他們都沒有工作。例如:

{r, fig.align="center"} 
library(pander) 
test <- as.data.frame(matrix(ncol = 5, nrow =5)) 
test[1] <- 1 
pander(test, justify = "center") 

添加fig.align = "center"不工作而且也不justify = "center"

有誰知道一種解決方法嗎?

enter image description here

回答

3

您可以只添加普通的HTML標記居中表(如<center>):

--- 
title: "test" 
output: 
    html_document: default 
    pdf_document: default 
--- 

<center> 

```{r, fig.align="center"} 
library(pander) 
test <- as.data.frame(matrix(ncol = 5, nrow =5)) 
test[1] <- 1 
pander(test, justify = "center") 
``` 

</center> 

如果你想同時顯示代碼和居中表,但不希望代碼居中,重複該塊,但不要第一次評估,然後不要第二次回顯。

下面是一個例子:

enter image description here


另外,添加自定義CSS文件,你的時尚選擇,並添加到您的標題。

實施例的CSS(保存爲 「test.css」):

table { 
    margin:1em auto; 
} 

實施例報頭:

--- 
title: "test" 
output: 
    html_document: 
    css: test.css 
---