R:knitr:pander:将标题与表格对齐

时间:2016-04-27 11:28:41

标签: r knitr pander

我试图将标题中心对齐到Rmarkdown文件中的pandoc表(输出到PDF)。该表以页面为中心,我希望标题同样居中。我似乎无法在pander / pandoc.table中找到一个选项,这让我在Rmarkdown中执行此操作,我在Rstudio / Knitr中编写。我目前唯一的解决方案是包含一串...... nbsp;

我已经检查了panderOptions,并且我也通过在yaml标头中插入代码来跟踪xtable caption alignment left aligned with table or centered (using knitr)中的评论(没有成功)。并且,我已按照此处的建议添加了换行符:Issue with creating PDf file with Pander+Knitr: Error when putting table with caption and plot directly next to each other

非常欢迎任何建议。

谢谢, 理查德

Rmarkdown doc:

header-includes:
 - \usepackage[
    singlelinecheck=false,
    justification=centering
    ]{caption}
output:
    pdf_document 
---

```{r table2, echo=FALSE, message=FALSE, warnings=FALSE, results='asis'}
library(pander)
panderOptions('keep.line.breaks', TRUE )
table2 <- "HHHH member | Description of future    
            H11111                | standard model    
            H22222                | low model      
            H33333                | decreasing projection"
df2 <- read.delim(textConnection(table2), header=FALSE, sep="|", strip.white=TRUE, stringsAsFactors=FALSE)
names(df2) <- unname(as.list(df2[1,]))
df2 <- df2[-1,] # remove first row
row.names(df2) <- NULL
pandoc.table(df2, 
             caption= "Table 2. Insert title here\n", style = "multiline", split.cells = c(20, 25))
```

系统: Linux Mint(17.1)/ Ubuntu Trusty RStudio:0.98.1103 Pander:0.6.0 Knitr:1.12.3

1 个答案:

答案 0 :(得分:0)

只需在顶部添加---解决了我的计算机上的问题。

---
header-includes:
 - \usepackage[
    singlelinecheck=false,
    justification=centering
    ]{caption}
output:
    pdf_document 
---

```{r table2, echo=FALSE, message=FALSE, warnings=FALSE, results='asis'}
library(pander)
panderOptions('keep.line.breaks', TRUE )
table2 <- "HHHH member | Description of future    
            H11111                | standard model    
            H22222                | low model      
            H33333                | decreasing projection"
df2 <- read.delim(textConnection(table2), header=FALSE, sep="|", strip.white=TRUE, stringsAsFactors=FALSE)
names(df2) <- unname(as.list(df2[1,]))
df2 <- df2[-1,] # remove first row
row.names(df2) <- NULL
pandoc.table(df2, 
             caption= "\\label{tab:MyLabel}Insert title here\n", style = "multiline", split.cells = c(20, 25))
```

In table&nbsp;\ref{tab:MyLabel} blabla

\autoref{tab:MyLabel}

编辑:在LaTeX样式中添加标签和对表的引用

相关问题