[英]R/Sweave/Latex - Place comment in table (xtable)
I created a table using R and sweave in LaTeX. 我使用R创建了一个表,并在LaTeX中进行了编织。 A sweave example:
编织示例:
\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}
The basic LaTeX structure of the table is 该表的基本LaTeX结构是
\begin{table}
\begin{tabular}{cc}
...
\end{tabular}
\end{table}
To save me a lot of work I use the print and xtable functions in R to create the table code in LaTeX. 为了节省大量工作,我使用R中的print和xtable函数在LaTeX中创建表代码。 But now I want to add some text between the \\end{tabular} and \\end{table} statements.
但是现在我想在\\ end {tabular}和\\ end {table}语句之间添加一些文本。 The add.to.row argument in the print function does not help, as statements are only placed before \\end{tabular}.
打印语句中的add.to.row参数无济于事,因为语句仅放在\\ end {tabular}之前。 How can I solve this problem?
我怎么解决这个问题?
Many thanks in advance for your help. 在此先感谢您的帮助。
A way to do this is to use xtable, remove the table environment floating = FALSE and package threeparttable 一种方法是使用xtable,删除表环境float = 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.