2

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,
 add.to.row=list(pos=list(-1,0, nrow(myData)),
  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,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  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,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  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,
  add.to.row=list(pos=list(-1,0, nrow(myData2)),
  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.

2

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):

enter image description here

\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).

| improve this answer | |
1

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}

enter image description here

\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}

and add this line instead:

\captionsetup[subtable]{labelformat=empty}

This way, the captions' labels will be deleted.

enter image description here

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

| improve this answer | |
  • How do I switch off the Table1:, Table2: ,Table3: , Table4: in the caption? Also is there a way to select where to place a group of tables eg bottom of p3, p4, p7 ? – adam.888 Aug 3 '15 at 14:44
  • @adam.888 Please see my edit. – AboAmmar Aug 3 '15 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.