在xtable中显示多个脚注 [英] Show multiple footnotes in xtable

查看:144
本文介绍了在xtable中显示多个脚注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与这个问题xtable中显示脚注,尽管建议的更新解决方案对我不起作用.我认为这是因为我在自己的设置中缺少某些内容,因此是单独的问题.我不认为问题是这个问题中描述的,因为我是在print调用中而不是xtable调用中使用sanitize.text.function.

My question is very similar to this one on showing footnotes in xtable, although the suggested updated solution isn't working for me. I presume this is because I am missing something in my own setup, hence the separate question. I don't think the issue is what is described in this question, as I am using the sanitize.text.function in the print call rather than the xtable call.

下面是PDF输出的图像.可以看出,实际脚注文本即使在渲染两次后也不会出现在PDF输出中.但是,出现脚注上标要做.我正在使用RStudio中的编织"按钮进行渲染.

Below is an image of the PDF output. As can be seen, the actual footnote text does not appear in the PDF output, even after rendering twice. The footnote superscripts do appear, however. I am rendering using the "Knit" button in RStudio.

如何获取要显示的实际脚注文本?

How can I get the actual footnote text to show?

PDF输出:

我在.Rmd文件中的代码如下.

My code from the .Rmd file is below.

---
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}

推荐答案

最后是通过反复试验发现的简单修补程序.

A simple fix in the end, found through trial-and-error.

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

To make the footnotes appear, the longtable LaTeX package and environment need to be used. I added them into the header-includes part of the YAML header and then the code ran as expected.

.Rmd文件中使用以下代码使脚注出现:

Using the following code in the .Rmd file made the footnotes appear:

---
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)
    }
  )
```

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

The generated table looks like this, with footnotes at the bottom of the page:

这篇关于在xtable中显示多个脚注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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