I have data tables (d1 and d2) which I would like to print side by side or on top of each other in latex with their own individual titles. Is it possible to do that directly wit
See Alan Munn's answer to a similar question on 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
<>=
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
<>=
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}