# Two tables side-by-side in LaTeX that will page break

I am creating a .Rnw file in Rstudio. I then knit it using:

knit("code.Rnw","code.tex")


I am trying to get two tables side-by-side. In case they are long, I would like them to automatically page break. I have tentative syntax that seems to work (when using the \quad command) as shown below:

\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage{longtable}

\begin{document}

<<echo=FALSE,results='asis'>>=
library(xtable)
@

\begin{tabular}{cc}
\hline
& vals \\
\hline
a & 3.39 \\
b & 4.35 \\
c & 6.16 \\
d & 9.17 \\
e & 2.82 \\
\hline
\end{tabular}
\quad % separates first and second table
\begin{tabular}{cc}
\hline
& vals \\
\hline
a & 3.39 \\
b & 4.35 \\
c & 6.16 \\
d & 9.17 \\
e & 2.82 \\
\hline
\end{tabular}

\end{document}


This creates the desired output as follows:

However, I am running across a problem when the tables become long. In the example above, there were only 5 rows per table. However, if I increase the number of rows so that each table can no longer fit on a single page, then rather than automatically page-break, it will simply run off the page. It looks something like this (there are more rows, y2, z2, etc, but these simply run off the page):

I tried to remedy this problem by using the "longtable" option (instead of the "tabular" option), as this is supposed to help with page-breaks:

\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage{longtable}

\begin{document}

<<echo=FALSE,results='asis'>>=
library(xtable)
@

\begin{longtable}{cc} % CHANGED FROM "TABULAR" TO "LONGTABLE"
\hline
& vals \\
\hline
a & 3.39 \\
b & 4.35 \\
c & 6.16 \\
d & 9.17 \\
e & 2.82 \\
\hline
\end{longtable} % CHANGED FROM "TABULAR" TO "LONGTABLE"
\quad % separates first and second table
\begin{longtable}{cc} % CHANGED FROM "TABULAR" TO "LONGTABLE"
\hline
& vals \\
\hline
a & 3.39 \\
b & 4.35 \\
c & 6.16 \\
d & 9.17 \\
e & 2.82 \\
\hline
\end{longtable} % CHANGED FROM "TABULAR" TO "LONGTABLE"

\end{document}


Even though it did solve the page-break issue (prevented text from falling off the page) in long table, it also made the tables no longer side by side (instead, placing them top to bottom). This was the undesired output:

My question therefore is: How can I retain the side-by-side format of the two tables, while also allowing page-breaks?

EDIT:

I accepted an answer here, although my real question has a second problem with it. I originally did not include it to keep my problem simple, but realize that if I only state one part of the problem, then the solutions will not really solve my set of problems.

Hence, I opened a new post with my more-complete question here: (Two tables (not hard-coded) side-by-side in LaTeX that will page break).

• If you are entering all the data by hand, you could divide the data into sections. – John Kormylo Jun 30 '15 at 20:02
• As an alternative to longtable, one could put both tabulars into a minipage in a savebox, then use \clipbox from the adjustbox package to crop it into sections. See tex.stackexchange.com/questions/204703/… (different problem, same solution). – John Kormylo Jun 30 '15 at 20:12
• @JohnKormylo Thank you! I am not entering the data by hand. I apologize for not specifying that. I opened a more thorough question here (tex.stackexchange.com/questions/253171/…) – luckButtered Jul 1 '15 at 13:35

You can still use a longtable as this:

\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage{longtable}
\begin{document}

\begin{longtable}{cc p{1em} cc}
\cline{1-2} \cline{4-5}
& vals&  &   & vals\\   \cline{1-2} \cline{4-5}
a & 3.39&  & a & 3.39\\
b & 4.35&  & b & 4.35\\
c & 6.16&  & c & 6.16\\
d & 9.17&  & d & 9.17\\
e & 2.82&  & e & 2.82\\   \cline{1-2} \cline{4-5}
\end{longtable}

And if the tables are of different lengths:
\begin{longtable}{cc p{1em} cc}
\cline{1-2} \cline{4-5}
& vals&  &   & vals\\   \cline{1-2} \cline{4-5}
a & 3.39&  & a & 3.39\\
b & 4.35&  & b & 4.35\\
c & 6.16&  & c & 6.16\\
d & 9.17&  & d & 9.17\\
e & 2.82&  & e & 2.82\\  \cline{4-5}
a & 3.39&  & & \\
b & 4.35&  & & \\
c & 6.16&  & & \\
d & 9.17&  & & \\
e & 2.82&  & & \\
\cline{1-2}
\end{longtable}
\end{document}


• Thank you this is very helpful. I am wondering if this solution can be generated automatically (not hardcoded) from a data table? – luckButtered Jun 30 '15 at 23:50
• For example, to reproduce my tables above, I could do: library(xtable); set.seed(1); myDF = data.frame(vals=runif(5, 1, 10)); row.names(myDF) = letters[1:5]; print(xtable(myDF),floating=FALSE,tabular.environment = "tabular"); – luckButtered Jun 30 '15 at 23:52
• I accepted this answer to the current question, and opened a more thorough question here (tex.stackexchange.com/questions/253171/…). Thanks again. – luckButtered Jul 1 '15 at 13:36