问题
I created a table using R and sweave in 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
\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. But now I want to add some text between the \end{tabular} and \end{table} statements. The add.to.row argument in the print function does not help, as statements are only placed before \end{tabular}. How can I solve this problem?
Many thanks in advance for your help.
回答1:
A way to do this is to use xtable, remove the table environment floating = FALSE and package 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
来源:https://stackoverflow.com/questions/19904105/r-sweave-latex-place-comment-in-table-xtable