问题
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
回答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)
回答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.
回答3:
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.
来源:https://stackoverflow.com/questions/9949929/r-latex-wide-table