使用xtable和tabular.environment将\ footnote {}插入标头 [英] inset \footnote{} into header with xtable and tabular.environment

查看:139
本文介绍了使用xtable和tabular.environment将\ footnote {}插入标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以控制xtable中的add.to.row命令在LaTeX表输出标题中放置\footnote{}吗?

Can I control the add.to.row command in xtable to place an \footnote{} in the LaTeX table output header?

这就是我已经走了多远. (我想使用xtable而不是'Hmisc'找到解决方案)

This is how far I've gotten it. (I would like to find a solution using xtable and not `Hmisc')

require(xtable)
x <- matrix(rnorm(60), ncol = 10)
x.big <- xtable(x,label='tabbig', caption='Example of longtable')
names(x.big) <- LETTERS[1:10]
print(x.big,tabular.environment='longtable',floating=FALSE, 
      add.to.row = list(pos = list(seq(1,nrow(x.big), by = 2), 0, 1),
      command = c("\\rowcolor[gray]{.95} ", "\\hline \\endhead ", 
      "\\footnote{This is the first footnote that I would like to have 
      in the headder next to `I'.}") ) )

然后我将输出用于一个小的乳胶文件中.像这样:

then I use the output in a small latex file. Like this:

\documentclass{article}
\usepackage{longtable} 
\usepackage{colortbl} 
\usepackage[landscape]{geometry}

\begin{document}
I
\vspace{100 mm}

% latex table generated in R 2.15.1 by xtable 1.7-0 package
% Sun Dec  2 15:38:26 2012
\begin{longtable}{rrrrrrrrrrr}
  \hline
 & A & B & C & D & E & F & G & H & I & J \\ 
  \hline \endhead  \hline
1 & 0.57 & -0.21 & 1.11 & 0.15 & -0.47 & 0.77 & 0.26 & 2.08 & 0.65 & -1.62 \\ 
   \rowcolor[gray]{.95}  \footnote{This is the first footnote that I would like to have in the headder next to `I'.}2 & -0.45 & -0.06 & 0.13 & 0.20 & 0.26 & 0.48 & 0.07 & 0.45 & -0.51 & 1.26 \\ 
  3 & -0.23 & -0.68 & 0.17 & -0.92 & -0.44 & -0.43 & -0.63 & 1.84 & 0.08 & 1.21 \\ 
   \rowcolor[gray]{.95} 4 & -1.60 & -0.69 & -0.11 & 2.12 & -0.12 & -1.81 & -1.51 & 0.67 & 0.22 & 0.43 \\ 
  5 & -0.26 & 0.14 & 0.86 & -0.78 & -2.04 & 1.17 & -1.48 & -0.38 & 0.80 & 1.49 \\ 
   \rowcolor[gray]{.95} 6 & -0.53 & -0.43 & -0.84 & 0.06 & -0.87 & 1.13 & -0.56 & 0.30 & -0.96 & 1.75 \\ 
   \hline
\hline
\caption{'Example of longtable'}
\label{tabbig}
\end{longtable}

\end{document}

这将产生此表,

推荐答案

我认为您无法使用 add.to.row参数来操作标头.

I think you can't manipulate the header using the add.to.row argument.

但是为什么不消毒呢?

这是我的解决方案:想法是在标头(此处为脚注)中放置标签,并使用sanitize选项对其进行更改.

Here my solution : The idea is to put a tag in the header (footnote here) and to change it using sanitize option.

x <- matrix(rnorm(60), ncol = 10)
x.big <- xtable(x,label='tabbig', caption='Example of longtable')
names(x.big) <- LETTERS[1:10]
names(x.big)[9] <- paste('I','footnote')    # I put the tag on I letter 
print(x.big,tabular.environment='longtable',floating=FALSE,
      sanitize.text.function=function(str)gsub("footnote","\\footnote{my tricky footnote !!}",str,fixed=TRUE))

通过使用许多标签,您可以轻松地将解决方案扩展到许多脚注.

You can easily extend the solution to many footnots by using many tags.

您可以轻松地将thes ame技巧用于多个注释,例如:

You can easily use thes ame trick for multiple notes, like this :

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,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 idea is to assign the same string after the regular expression substitution.

这篇关于使用xtable和tabular.environment将\ footnote {}插入标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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