【问题标题】:inset \footnote{} into header with xtable and tabular.environment将 \footnote{} 插入带有表和 tabular.environment 的标题中
【发布时间】:2012-12-02 23:58:37
【问题描述】:

能否控制xtable 中的add.to.row 命令在LaTeX 表输出标题中放置\footnote{}

这就是我得到它的程度。 (我想找到使用xtable 而不是`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'.}") ) )

然后我在一个小的乳胶文件中使用输出。像这样:

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

这会产生这张表,

【问题讨论】:

    标签: r latex xtable


    【解决方案1】:

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

    但为什么不消毒呢?

    这是我的解决方案:想法是在标题中放置一个标签(footnote 这里)并使用 sanitize 选项进行更改。

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

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

    更新,多脚注的情况

    您可以轻松地对多个音符使用相同的技巧,如下所示:

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

    想法是在正则表达式替换后分配相同的字符串。

    【讨论】:

    • 有没有人知道解决\footnote{}\endhead之间冲突的聪明方法?
    • @Eric 最好问一个真正的问题,不是吗?
    • 你是对的。尽管我确实使用\footnotemark\footnotetext 解决了它,如longtable manual, p. 8 中所述。另外,described here.
    • 太棒了!这也适用于 Lyx。我在那里粘贴了我的 lyx 文件:sanitizefootnote.lyx.
    • @agstudy 如何将解决方案扩展到许多脚注?我尝试在sanitize.text.function 中使用两组gsub 函数,但没有奏效。
    猜你喜欢
    • 1970-01-01
    • 2019-11-28
    • 2013-01-15
    • 2014-11-23
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多