3

I'm writing a report with sweave. I have to put-in a very wide table:

from R

dim(myData)
> 50 60

The R code I wrote to generate the LaTex table is:

print(xtable(myData, caption="my wide table", label="tab:myTab", digits=3),
       tabular.environment="longtable", caption.placement="top",
    ## floating.environment="sidewaystable", ## a trial
       size="\\tiny", table.placement="", floating=FALSE)

The problem is that the table is too wide for the dimension of the page, so, is there a way to divide the table in different pages, such as LaTeX longtable environment but, by the width??

I hope I have been able to explain my problem.

Regards

Riccardo

Riccardo
  • 1,885
  • 3
  • 15
  • 22
  • There are ways to scale a table to fit the page width, which might help in combination with the landscape options below. See http://tex.stackexchange.com/questions/10863/is-there-a-way-to-slightly-shrink-a-table-including-font-size-to-fit-within-th and http://tex.stackexchange.com/questions/35987/scaling-a-table-to-fit-an-entire-page – PaulHurleyuk Mar 31 '12 at 09:22
  • I have already used but I have too much rows and columns. – Riccardo Apr 02 '12 at 14:24

3 Answers3

2

Another useful approach is to use the resizebox function to scale the table to fit page width. I find this to be much nicer than using the blunt tool of \small or \tiny:

\begin{table}[t]
  \resizebox{\textwidth}{!}{%
    \centering
    \begin{tabular}{lllll}
      % Some stuff
    \end{tabular}}%Closing bracket 
  %Don't scale the caption!
  \caption{A table caption.}\label{T1.1}
\end{table}

I suspect that your table will still have to be split in two, but resizebox could be used in conjugation with @PaulHurleyuk answer.

csgillespie
  • 59,189
  • 14
  • 150
  • 185
1

If you can fit the columns into one page in landscape mode, the longtable environment will take care of the overflowing rows for you, including correct captioning.

If there is no way to re-arrange the table so it fits on your current landscape page, you could always make the page bigger (see the geometry package).

Since you are using Sweave, I suggest you take a look at my previous TeX.SX answer on the same subject, which defines the longtable caption in such a way that it behaves correctly.

Community
  • 1
  • 1
solarchemist
  • 438
  • 3
  • 13
  • I can not fit the columns or the rows into one single page. I read your link and I found it very interesting!! – Riccardo Apr 02 '12 at 14:26
  • Well, if there is no way to fit the tabular contents as-is, you will have to re-consider the layout of the table. Glad you found my Sweave code of value. – solarchemist Apr 03 '12 at 05:14
  • Just noticed your comment at the subsetting answer. Don't forget to accept that answer. Good luck Sweaving. – solarchemist Apr 03 '12 at 05:17
1

You could create multiple tables manually by subsetting your data

Table 1 (assuming first three columns should be in both

print(xtable(myData[,c(1:3,4:25)], caption="my wide table", label="tab:myTab", digits=3),
       tabular.environment="longtable", caption.placement="top",
       size="\\tiny", table.placement="", floating=FALSE)

Table 2

print(xtable(myData[,c(1:3,25:50)], caption="my wide table", label="tab:myTab", digits=3),
       tabular.environment="longtable", caption.placement="top",
       size="\\tiny", table.placement="", floating=FALSE)
PaulHurleyuk
  • 8,009
  • 15
  • 54
  • 78
  • Finally I used the way you suggested: to divide the wide table into smaller ones. I hoped to find some R/LaTeX trick to adapt the table to different pages... :( – Riccardo Apr 02 '12 at 14:37