在xtable中显示多个脚注

时间:2017-08-22 09:01:45

标签: r pdf latex xtable footnotes

我的问题与xtablesanitize.text.function中显示脚注非常相似,尽管建议的更新解决方案对我不起作用。我认为这是因为我在自己的设置中遗漏了一些东西,因此是一个单独的问题。我认为问题不是this one中描述的问题,因为我在print电话中使用xtable而不是.Rmd电话。

下面是PDF输出的图像。可以看出,即使在渲染两次之后,实际脚注文本也不会出现在PDF输出中。但是,脚注上标执行。我正在使用RStudio中的“Knit”按钮进行渲染。

如何才能显示实际的脚注文字?

PDF输出:

this question

--- title: "xtable footnotes" output: pdf_document: keep_tex: true fig_caption: true --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r results = "asis"} library(xtable) x <- matrix(rnorm(60), ncol = 10) x.big <- xtable(x,label = 'tabbig', caption = 'Example of xtable footnotes') names(x.big) <- LETTERS[1:10] names(x.big)[1] <- paste('A','footnote1') # I put the tag on A letter names(x.big)[9] <- paste('I','footnote2') # I put the tag on I letter print(x.big, type = "latex", sanitize.text.function = function(str){ str <- gsub("footnote1","\\footnote{my tricky footnote 1 !!}", str, fixed = TRUE) str <- gsub("footnote2","\\footnote{my tricky footnote 2 !!}", str, fixed = TRUE) } ) ``` 文件中的代码如下。

.tex

表格的\% latex table generated in R 3.4.1 by xtable 1.8-2 package \% Tue Aug 22 09:45:33 2017 \begin{table}[ht] \centering \begin{tabular}{rrrrrrrrrrr} \hline & A \footnote{my tricky footnote 1 !!} & B & C & D & E & F & G & H & I \footnote{my tricky footnote 2 !!} & J \\ \hline 1 & 1.13 & -0.00 & -0.14 & 0.83 & 0.58 & -0.65 & -1.12 & -2.04 & -0.64 & 0.50 \\ 2 & 0.13 & -0.65 & -1.11 & 0.06 & -1.32 & -0.28 & 0.96 & 1.19 & -0.41 & -0.51 \\ 3 & -0.73 & 0.16 & -0.26 & -1.50 & -1.34 & 0.84 & -0.28 & -0.02 & -0.98 & 1.13 \\ 4 & 0.33 & 0.89 & -1.08 & -0.89 & 1.16 & 1.70 & -0.77 & -0.21 & 1.01 & 0.22 \\ 5 & 0.86 & 0.19 & -0.94 & -1.36 & -2.49 & 0.62 & 0.87 & -1.17 & -0.24 & 0.17 \\ 6 & 0.19 & -0.15 & 0.20 & -0.56 & 0.04 & 1.20 & -0.72 & -1.39 & -1.30 & 0.03 \\ \hline \end{tabular} \caption{Example of xtable footnotes} \label{tabbig} \end{table} 输出如下:

$st->execute(array($sender, $receiver, $receiver, $sender));

1 个答案:

答案 0 :(得分:0)

最后一个简单的修复,通过反复试验找到。

要显示脚注,需要使用longtable LaTeX包和环境。我将它们添加到header-includes标题的YAML部分,然后代码按预期运行。

使用.Rmd文件中的以下代码显示脚注:

---
title: "xtable footnotes"
output: 
    pdf_document:
        keep_tex: true
        fig_caption: true
header-includes:
    - \usepackage{longtable}  

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r results = "asis"}
library(xtable)

x <- matrix(rnorm(60), ncol = 10)

x.big <- xtable(x,label = 'tabbig', caption = 'Example of xtable footnotes')
names(x.big) <- LETTERS[1:10]

names(x.big)[1] <- paste('A','footnote1')
names(x.big)[9] <- paste('I','footnote2') 

# tabular.environment needs to be 'longtable'
# \usepackage{longtable} needs to be in the YAML header at the start of the .Rmd file

print(x.big,
      tabular.environment = 'longtable',
      floating = FALSE,
      sanitize.text.function = function(str){
        str <- gsub("footnote1","\\footnote{my tricky footnote 1 !!}", str, fixed = TRUE)
        str <- gsub("footnote2","\\footnote{my tricky footnote 2 !!}", str, fixed = TRUE)
    }
  )
```

生成的表格如下所示,页面底部有脚注:

fixed table with footnotes