# Sweave: Floating Text and four tables anchored at bottom of the first page

I am trying to create a document that contains floating text that can extend over more than one page in length together with four tables that are anchored at the bottom of the first page (top left table, top right table, bottom left table, bottom right table). I tried the code below, but the tables do not align correctly at the bottom of the first page, but spill over to the second page and are all one on top of another.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
\title{Floating Text and four tables anchored at bottom of the first page}
\author{}
\date{}
\begin{document}
\maketitle

Text
ttttttttttttttttttttttttttttttttttttttttttttttttt
ttttttttttttttttttttttttttttttttttttttttttttttttttttt
ttttttttttttttttttttttttttttttttttttttttttttttttttttt
tttttttttttttttttttttttttttttttttttttttttttttttttttttttt

<<echo=FALSE,results=tex>>=
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
@

\begin{table}[b]

\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
library("xtable")
print(xtable(myData),
floating=FALSE,
hline.after=NULL,
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The top left table}
\end{minipage}

\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
floating=FALSE,
hline.after=NULL,
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The top right table}
\end{minipage}

\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
floating=FALSE,
hline.after=NULL,
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The bottom left table}
\end{minipage}

\begin{minipage}{.45\textwidth}
\centering
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
floating=FALSE,
hline.after=NULL,
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\captionof{table}{The bottom right table}
\end{minipage}

\end{table}

\end{document}


I would be grateful for your help.

A couple of things:

• Empty lines in TeX mean something: A paragraph break. That's why you have tables stacked one on top of the other (vertically). Remove the blank lines to make sure things stack next to one another (horizontally).

• Place the table before the actual text, as you want it to appear at the bottom of the first page. If you place it after the text and the text spills over to the second page, your table will necessarily end up on the second page (or later).

Here is a minimal example showing what you should use (with \SweaveTable instead of your Sweave input):

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage{lipsum}% Just for this example
\title{Floating Text and four tables anchored at bottom of the first page}
\author{}
\date{}

\newcommand{\SweaveTable}{%
\begin{tabular}{*{4}{c}}
\toprule
& A & B & C \\
\midrule
1 & 19 & 23 & 16 \\
2 & 89 & 74 & 39 \\
3 & 23 & 44 & 67 \\
\bottomrule
\end{tabular}%
}

%\renewcommand{\bottomfraction}{0.5}
\begin{document}
\maketitle

\begin{table}[!b]
\begin{minipage}{.5\linewidth}
\centering
\SweaveTable
\captionof{table}{The top left table}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\SweaveTable
\captionof{table}{The top right table}
\end{minipage}

\begin{minipage}{.5\linewidth}
\centering
\SweaveTable
\captionof{table}{The bottom left table}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\SweaveTable
\captionof{table}{The bottom right table}
\end{minipage}
\end{table}

\lipsum[1-7]

\end{document}


Depending on the size of the table, you may have to adjust the floating parameters (for example, the \bottomfraction).

Another implementation using the subcaption package. Without any settings, the captions' labels would appear as (a), (b), (c), and (d). So, we have to pass a few parameters to the subcaption package to get the normal appearance of a table. Namely, the following two commands achieve this:

\renewcommand{\thesubtable}{Table \arabic{subtable}}
\captionsetup[subtable]{labelformat=simple, labelsep=colon}


\documentclass{article}
\usepackage{booktabs,caption,subcaption}
\usepackage{lipsum}% Just for this example

\renewcommand{\thesubtable}{Table \arabic{subtable}}
\captionsetup[subtable]{labelformat=simple, labelsep=colon}

\title{Floating Text and four tables anchored at bottom of the first page}
\author{}
\date{}

\newcommand{\SweaveTable}{%
\begin{tabular}{*{4}{c}}
\toprule
& A & B & C \\
\midrule
1 & 19 & 23 & 16 \\
2 & 89 & 74 & 39 \\
3 & 23 & 44 & 67 \\
\bottomrule
\end{tabular}%
}

\begin{document}
\maketitle

\begin{table}[!b]
\begin{subtable}[b]{.5\linewidth}\centering
\captionof{table}{The top left table}
\SweaveTable
\end{subtable}%
\begin{subtable}[b]{.5\linewidth}\centering
\captionof{table}{The top right table}
\SweaveTable
\end{subtable}%
\medskip

\begin{subtable}[b]{.5\linewidth}\centering
\captionof{table}{The bottom left table}
\SweaveTable
\end{subtable}%
\begin{subtable}[b]{.5\linewidth}\centering
\captionof{table}{The bottom right table}
\SweaveTable
\end{subtable}%
\end{table}

\lipsum[1-7]

\end{document}


Edit:

As per the OP's comment, switching off the Table1:, Table2: ,Table3: , Table4: in the caption is easy. One should delete the following two lines:

\renewcommand{\thesubtable}{Table \arabic{subtable}}
\captionsetup[subtable]{labelformat=simple, labelsep=colon}


\captionsetup[subtable]{labelformat=empty}

For placing the tables at some certain pages, the afterpage package may be of interest. Currently, I have no details to provide an example.