From c699f03513d2a2e049cb9beb7da90e4c927d4029 Mon Sep 17 00:00:00 2001 From: roosen Date: Tue, 7 Feb 2012 09:11:53 +0000 Subject: [PATCH] Added "scalebox" argument to print.xtable. Commented out longtable example with repeated headers as the column name alignment was off. git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@28 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/NEWS | 5 ++- pkg/R/print.xtable.R | 9 ++++- pkg/inst/doc/xtableGallery.snw | 68 ++++++++++++++++++++-------------- pkg/man/print.xtable.Rd | 2 + 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/pkg/NEWS b/pkg/NEWS index 48e7441..1c407bd 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -13,13 +13,14 @@ * Added "booktabs" argument to use the "\toprule", "\midrule", and "\bottomrule" tags from the Latex "booktabs" package rather than using "\hline" for all horizontal lines. + * Added "scalebox" argument to include a "\scalebox" clause around + the tabular environment with the specified value used as the + scaling factor. * Changed the "print.xtable()" arguments to use "getOption()" to check the options for a default value. This was suggested since "print.xtable()" has a lot of arguments that the user will typically leave unchanged between tables. * Added an "is.null()" check on the "table.placement" argument. - * Added an example of header and footer specification with longtable - to the vignette. * Added examples using the new arguments to the vignette. 1.6-0 (2011-10-07) diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R index bae66a1..8c56c33 100644 --- a/pkg/R/print.xtable.R +++ b/pkg/R/print.xtable.R @@ -51,6 +51,7 @@ print.xtable <- function( rotate.rownames=getOption("xtable.rotate.rownames", FALSE), rotate.colnames=getOption("xtable.rotate.colnames", FALSE), booktabs = getOption("xtable.booktabs", FALSE), + scalebox = getOption("xtable.scalebox", NULL), ...) { # If caption is length 2, treat the second value as the "short caption" caption <- attr(x,"caption",exact=TRUE) @@ -206,7 +207,7 @@ print.xtable <- function( paste(c(attr(x, "align",exact=TRUE)[tmp.index.start:length(attr(x,"align",exact=TRUE))], "}\n"), sep="", collapse=""), sep="") - + ## fix 10-26-09 (robert.castelo@upf.edu) the following 'if' condition is added here to support ## a caption on the top of a longtable if (tabular.environment == "longtable" && caption.placement=="top") { @@ -222,6 +223,12 @@ print.xtable <- function( BTABULAR <- paste(BTABULAR,lastcol[1], sep="") # the \hline at the end, if present, is set in full matrix ETABULAR <- paste("\\end{",tabular.environment,"}\n",sep="") + + ## Add scalebox - CR, 7/2/12 + if (!is.null(scalebox)){ + BTABULAR <- paste("\\scalebox{", scalebox, "}{\n", BTABULAR, sep="") + ETABULAR <- paste(ETABULAR, "}\n", sep="") + } # BSIZE contributed by Benno in e-mail dated Wednesday, December 01, 2004 if (is.null(size) || !is.character(size)) { diff --git a/pkg/inst/doc/xtableGallery.snw b/pkg/inst/doc/xtableGallery.snw index da83911..c69c98e 100644 --- a/pkg/inst/doc/xtableGallery.snw +++ b/pkg/inst/doc/xtableGallery.snw @@ -430,7 +430,6 @@ print(xtable(anova(glm.D93)),size="small",floating=FALSE) \subsection{Long tables} Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble. -See Table \ref{tabbig}. <>= @@ -443,37 +442,40 @@ x.big <- xtable(x,label='tabbig', print(x.big,tabular.environment='longtable',floating=FALSE) @ -\subsubsection{Long tables with the header on each page} - -The {\tt add.to.row} argument can be used to display the header -for a long table on each page, and to add a "continued" footer -on all pages except the last page. See Table \ref{tabbig2}. - -<>= -library(xtable) -x<-matrix(rnorm(1000), ncol = 10) - -addtorow<-list() -addtorow$pos<-list() -addtorow$pos[[1]]<-c(0) -addtorow$command<-c(paste( - "\\hline \n", - " \\endhead \n", - " \\hline \n", - " {\\footnotesize Continued on next page} \n", - " \\endfoot \n", - " \\endlastfoot \n",sep="")) -x.big2 <- xtable(x, label = "tabbig2", - caption = "Example of longtable with the header on each page") -print(x.big2, tabular.environment = "longtable", floating = FALSE, -include.rownames=FALSE,add.to.row=addtorow,hline.after=c(-1) ) -@ +%% +%% The column name alignment is off in the following example. +%% It needs some revision before exposing it. - CR, 7/2/2012 +%% +% +%\subsubsection{Long tables with the header on each page} +% +%The {\tt add.to.row} argument can be used to display the header +%for a long table on each page, and to add a "continued" footer +%on all pages except the last page. +% +%<>= +%library(xtable) +%x<-matrix(rnorm(1000), ncol = 10) +%addtorow<-list() +%addtorow$pos<-list() +%addtorow$pos[[1]]<-c(0) +%addtorow$command<-c(paste( +% "\\hline \n", +% " \\endhead \n", +% " \\hline \n", +% " {\\footnotesize Continued on next page} \n", +% " \\endfoot \n", +% " \\endlastfoot \n",sep="")) +%x.big2 <- xtable(x, label = "tabbig2", +% caption = "Example of longtable with the header on each page") +%print(x.big2, tabular.environment = "longtable", floating = FALSE, +%include.rownames=FALSE, add.to.row=addtorow, hline.after=c(-1) ) +%@ \subsection{Sideways tables} Remember to insert \verb|\usepackage{rotating}| in your LaTeX preamble. Sideways tables can't be forced in place with the `H' specifier, but you can use the \verb|\clearpage| command to get them fairly nearby. -See Table \ref{tabsmall}. <<>>= x <- x[1:30,] @@ -485,6 +487,18 @@ print(x.small,floating.environment='sidewaystable') @ \clearpage +\subsection{Rescaled tables} +Specify a \code{scalebox} value to rescale the table. + +<<>>= +x <- x[1:20,] +x.rescale <- xtable(x,label='tabrescaled',caption='A rescaled table') +@ + +<>= +print(x.rescale, scalebox=0.7) +@ + \section{Suppressing Printing} By default the {\tt print} method will print the LaTeX or HTML to standard output and also return the character strings invisibly. The printing to diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd index 03faef6..1f7271e 100644 --- a/pkg/man/print.xtable.Rd +++ b/pkg/man/print.xtable.Rd @@ -32,6 +32,7 @@ rotate.rownames=getOption("xtable.rotate.rownames", FALSE), rotate.colnames=getOption("xtable.rotate.colnames", FALSE), booktabs = getOption("xtable.booktabs", FALSE), + scalebox = getOption("xtable.scalebox", NULL), ...)} \arguments{ \item{x}{An object of class \code{"xtable"}.} @@ -70,6 +71,7 @@ \item{rotate.rownames}{If \code{TRUE}, the row names are displayed vertically in LaTeX.} \item{rotate.colnames}{If \code{TRUE}, the column names are displayed vertically in LaTeX.} \item{booktabs}{If \code{TRUE}, the \code{toprule}, \code{midrule} and \code{bottomrule} tags from the LaTex "booktabs" package are used rather than \code{hline} for the horizontal line tags.} + \item{scalebox}{If not \code{NULL}, a \code{scalebox} clause will be added around the tabular environment with the specified value used as the scaling factor.} \item{...}{Additional arguments. (Currently ignored.)} } \details{ -- 2.39.2