简体   繁体   English

R-LaTeX宽桌

[英]R-LaTeX Wide table

I'm writing a report with sweave. 我正在用sweave写一份报告。 I have to put-in a very wide table: 我必须放入一张很宽的桌子:

from R 来自R.

dim(myData)
> 50 60

The R code I wrote to generate the LaTex table is: 我写的生成LaTex表的R代码是:

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?? 问题是该表对于页面的维度来说太宽了,所以,有没有办法将表分成不同的页面,例如LaTeX longtable环境,但是,宽度?

I hope I have been able to explain my problem. 我希望我能够解释我的问题。

Regards 问候

Riccardo 里卡多

Another useful approach is to use the resizebox function to scale the table to fit page width. 另一个有用的方法是使用resizebox函数来缩放表以适合页面宽度。 I find this to be much nicer than using the blunt tool of \\small or \\tiny : 我发现这比使用\\small\\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. 我怀疑你的桌子仍然需要分成两部分,但resizebox可以与@PaulHurleyuk的答案结合使用。

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. 如果您可以在横向模式下将列装入一个页面,则longtable环境将为您处理溢出的行,包括正确的字幕。

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). 如果无法重新排列表格以使其适合您当前的横向页面,则可以始终使页面更大(请参阅geometry包)。

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. 由于您使用的是Sweave,我建议您查看我之前关于同一主题的TeX.SX答案,该答案定义了longtable标题,使其行为正确。

You could create multiple tables manually by subsetting your data 您可以通过对数据进行子集化手动创建多个表

Table 1 (assuming first three columns should be in both 表1(假设前三列应该在两者中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM