[R] Problem with xtable- rescaling a table

Ista Zahn istazahn at gmail.com
Sun Feb 5 15:59:30 CET 2012


Hi Tal,

Untested, but it should just be a matter of giving tabularx style formatting 
in the align option to xtable(), and then using "tabularx" as the 
tabular.environment argument to print.xtable()

see ?xtable and ?print.xtable for details.

Best,
Ista

On Sunday, February 05, 2012 01:16:38 PM Tal Galili wrote:

Dear Ista,


Do you happen to know of a way to use the {tabularx} LaTeX pacakge, so to have 
it work with xtables?


I would rather have my columns adjust themselves then to rotate my table. 


Thank you in advance,
Tal






----------------Contact 
Details:-------------------------------------------------------
Contact me: Tal.Galili at gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | 
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------





On Sat, Feb 4, 2012 at 10:46 PM, Ista Zahn <istazahn at gmail.com> wrote:

Hi Aurelien,

You just need to put the \caption outside the scalebox command, like this:


 \documentclass[11pt]{report}
\usepackage{rotating}
 %\usepackage[counterclockwise]{rotating}
\usepackage{graphics}
\usepackage{float}


\pagestyle{empty}


\begin{document}
\begin{sidewaystable}[ht]

\centering

\scalebox{0.7}{

% latex table generated in R 2.13.1 by xtable 1.6-0 package
% Wed Feb  1 10:29:25 2012
\begin{tabular}{ccc}
 \hline
 & V1 & V2 \\
 \hline
 &  &  \\
 6.91 & 500.00 & 4.00 \\
 400.00 &  & 400.00 \\
  \hline
\end{tabular}
}
\caption{Title}
\end{sidewaystable}
\end{document}


Best,
Ista




On Wednesday, February 01, 2012 10:37:47 AM Aurélien PHILIPPOT wrote:

Thanks Ista.
Your suggestion works.
When I make the option floating=F, the caption no longer appears in the Tex
code generated by xtable. If I had \caption {Title} in the code, it does not
seem to work.
 \documentclass[11pt]{report}
\usepackage{rotating}
 %\usepackage[counterclockwise]{rotating}
\usepackage{graphics}
\usepackage{float}


\pagestyle{empty}


\begin{document}
\begin{sidewaystable}[ht]
\scalebox{0.7}{


% latex table generated in R 2.13.1 by xtable 1.6-0 package
% Wed Feb  1 10:29:25 2012
\begin{tabular}{ccc}
 \hline
 & V1 & V2 \\
 \hline
 &  &  \\
 6.91 & 500.00 & 4.00 \\
 400.00 &  & 400.00 \\
  \hline
\end{tabular}
\caption{Title}
}
\end{sidewaystable}
\end{document}


So, I am faced with a dilemma. If I use the code from my previous email, I
could have the landscape and the title work, but if I incorporate scalebox in
Latex it does not work. If I use the floating=F solution, I can rescale and
landscape, but I have troubles having a caption. That's weird.


Best,
Aurelien






2012/2/1 Ista Zahn <istazahn at gmail.com>
Hi,

It looks like you need scalebox inside the sidewaystable environment. If you
must use scalebox, one solution is to use floating=FALSE when you call
print.xtable, and insert the table environment directly in LaTeX, like this:

\begin{sidewaystable}[ht]
\scalebox{0.7}{
<<code1,results=tex,echo=false>>=
print(outfile, include.rownames=F, floating = FALSE)
@
}
\end{sidewaystable}

Alternatively, since the size of the table is determined by the size of the
text in the table, you can just tell LaTeX to use a smaller font, e.g.

<<results=tex,echo=false>>=
print(outfile, include.rownames=F, floating.environment='sidewaystable', size
= "scriptsize")
@

Best,
Ista


On Tuesday, January 31, 2012 11:41:27 PM Aurélien PHILIPPOT wrote:
> Dear R users,
> I am new to Latex and I am using the R package xtable to generate tables.
> I want to produce a table that is very long.  in the landscape format, but
> I would need to rescale the table so that it fits in the page. xtable
> enables me to have the landscape format, but I cannot rescale it, and there
> seems to be a problem, if I use scalebox in Latex on my output produced
> with stable and the option sidewaystable. Do you know any way to achieve
> this result with xtable or another R package?
>
> Let's look at the following example:
> In R, I use the following code
>
> ##############
> outfile<- matrix(nrow=3, ncol=3)
> outfile[2,1]<- 6.912
> outfile[3,1]<- 400
> outfile[2,2]<- 8.9722
> outfile[2,2]<- 500
> outfile[2,3]<- 4.00
> outfile[3,3]<- 400
>
>
>
> library(xtable)
> outfile<- data.frame(outfile)
> colnames(outfile)<- c(" ","V1", "V2")
>
> outfile<- xtable(outfile, caption= "Title", include.rownames=F,
> align=rep("c", 4), digit=2)
> print(outfile, include.rownames=F, floating.environment='sidewaystable')
> ################
>
> I was wondering if it is possible to rescale in Latex when  the code was
> generated through xtable.  Indeed, when I run the latex table obtained from
> xtable, and use scale box, it does not work (and the problem comes from
> scalebox, which works otherwise).
>
> \documentclass[11pt]{report}
>
> \usepackage{rotating}
>
>  %\usepackage[counterclockwise]{rotating}
>
> \usepackage{graphics}
>
> \usepackage{float}
>
>
> \pagestyle{empty}
>
>
> \begin{document}
>
> \scalebox{0.70} { %resize
>
>
> % latex table generated in R 2.13.1 by xtable 1.6-0 package
>
> % Tue Jan 31 23:26:10 2012
>
> \begin{sidewaystable}[ht]
>
> \begin{center}
>
> \begin{tabular}{ccc}
>
>   \hline
>
>   & V1 & V2 \\
>
>   \hline
>
>  &  &  \\
>
>   6.91 & 500.00 & 4.00 \\
>
>   400.00 &  & 400.00 \\
>
>    \hline
>
> \end{tabular}
>
> \caption{Title}
>
> \end{center}
>
> \end{sidewaystable}
>
>
> }
>
> \end{document}
>
>
>
> Thanks a lot for any advice.
>
>
> Best,
>
> Aurelien
>

>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list