![](/img/trans.png)
[英]Vertical lines/borders in generated table is not continuous (R+Latex+Sweave+xtable)
[英]R/Sweave/Latex - Place comment in table (xtable)
我使用R创建了一个表,并在LaTeX中进行了编织。 编织示例:
\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}语句之间添加一些文本。 打印语句中的add.to.row参数无济于事,因为语句仅放在\\ end {tabular}之前。 我怎么解决这个问题?
在此先感谢您的帮助。
一种方法是使用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.