我有数据表(d1和d2),我想在乳胶中并排或相互打印各自的标题.是否有可能直接这样做xtable()?这两个表应该是不同的,即我们可以将它们称为表x(a)和表x(b),但它们应该相邻或堆叠.
chl*_*chl 14
我会建议保存结果在不同的文件(见两个单独的表file=选项print.xtable()),然后input他们与任何命令你的LaTeX文档您找到适合您的布局(tabular,subfloat,minipage等).这是我一般的做法,虽然我通常依赖于Hmisc包中的LaTeX工具.如果您只想将它们作为独立PDF打印,请使用该standalone文档的类.
所以,这是一个例子:
data(tli)
fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli)
print(xtable(fm1), file="ta.tex", floating=FALSE)
print(xtable(head(tli, n=5)), file="tb.tex", floating=FALSE)
Run Code Online (Sandbox Code Playgroud)
然后,快速tex包装器(编译pdflatex):
\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\begin{table}[ht]
\centering
\subfloat[Table x(a)]{\label{tab:tab1a}\scalebox{.5}{\input{./ta}}}\quad
\subfloat[Table x(b)]{\label{tab:tab1b}\scalebox{.5}{\input{./tb}}}
\caption{Caption about here}
\label{tab:tab1}
\end{table}
\end{document}
Run Code Online (Sandbox Code Playgroud)
结果如下:

删除\scalebox默认(堆叠)布局的命令,除非它们足够窄以适合其默认大小,如@David所述.

MYa*_*208 10
请参阅Alan Munn对tex.stackexchange.com上类似问题的回答.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
\title{Side-by-side xtables}
\author{}
\date{}
\begin{document}
\maketitle
First some R code to create some data.
<<>>=
myData <- matrix(c(19,89,23,23,74,44,16,39,67),ncol=3,byrow=TRUE)
colnames(myData) <- c("A","B","C")
rownames(myData) <- c("1","2","3")
myData2 <- myData * 2
@
Now we place the data in two side-by-side tables:
\begin{table}[htb]
\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
library("xtable")
print(xtable(myData),
floating=FALSE,
hline.after=NULL,
add.to.row=list(pos=list(-1,0, nrow(myData)),
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The first table}
\end{minipage}
\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
floating=FALSE,
hline.after=NULL,
add.to.row=list(pos=list(-1,0, nrow(myData2)),
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The second table}
\end{minipage}
\end{table}
\end{document}
Run Code Online (Sandbox Code Playgroud)
