【问题标题】:R/Sweave/Latex - Place comment in table (xtable)R/Sweave/Latex - 在表格中放置评论 (xtable)
【发布时间】:2013-11-11 10:31:07
【问题描述】:

我使用 R 创建了一个表格,并在 LaTeX 中 sweave。一个摆动的例子:

\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}

<<label=tab1, echo=FALSE, results=tex>>=
library(xtable)
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
mData <- data.frame(employee, salary) 
print(xtable(mData, caption = "Salary", align="ccc"), caption.placement="top", hline.after = c(c(-1, 0), nrow(mData)), include.rownames=FALSE) 
@

\end{document}

表格的基本LaTeX结构是

\begin{table}
\begin{tabular}{cc}
...
\end{tabular}
\end{table}

为了节省大量工作,我使用 R 中的 print 和 xtable 函数在 LaTeX 中创建表格代码。但现在我想在 \end{tabular} 和 \end{table} 语句之间添加一些文本。 print 函数中的 add.to.row 参数没有帮助,因为语句只放在 \end{tabular} 之前。我该如何解决这个问题?

非常感谢您的帮助。

【问题讨论】:

  • 我只需要编辑 xtable 对象——将它保存到一个变量中,然后在表格和表格环境之间插入所需的文本。

标签: r latex sweave xtable


【解决方案1】:

一种方法是使用xtable,删除表环境floating = FALSE并打包threeparttable

\documentclass{article}
\usepackage[para,online,flushleft]{threeparttable}
\begin{document}
\SweaveOpts{concordance=TRUE}

<<label=tab1, echo=FALSE, results=tex>>=
library(xtable)
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
mData <- data.frame(employee, salary) 
options(xtable.comment = FALSE)
xt<-xtable(mData, caption = "Salary", align="ccc") 
print(xt,floating = FALSE,
    caption.placement="top",
    hline.after = c(c(-1, 0), nrow(mData)),
    include.rownames=FALSE,
    file="test.tex"
    )
@


\begin{table}[h]
\caption{A table with notes in the end}
  \begin{center}
     \begin{threeparttable}
       % INPUT YOUR TEX HERE :
       \input{test.tex}
     \begin{tablenotes}
       \item[1] aaaa; \item[2] bbbb
     \end{tablenotes}
    \end{threeparttable}
   \end{center}
 \label{table:tablewithnotes}
 \end{table}     
\end{document}`enter code here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 2013-07-29
    相关资源
    最近更新 更多