]> git.donarmstrong.com Git - xtable.git/blobdiff - pkg/R/print.xtable.R
Added the "width" argument for use with "tabular*" or "tabularx" tabular environments.
[xtable.git] / pkg / R / print.xtable.R
index 8c56c33875fe660c5ef4fde002e50ea7ab39db8b..94cb18d0b04340167e2c7f1d9050373b3ecd28fd 100644 (file)
@@ -52,6 +52,7 @@ print.xtable <- function(
   rotate.colnames=getOption("xtable.rotate.colnames", FALSE),\r
   booktabs = getOption("xtable.booktabs", FALSE),\r
   scalebox = getOption("xtable.scalebox", NULL),\r
+  width = getOption("xtable.width", NULL),\r
   ...) {\r
   # If caption is length 2, treat the second value as the "short caption"\r
   caption <- attr(x,"caption",exact=TRUE)\r
@@ -203,10 +204,20 @@ print.xtable <- function(
       while ( attr(x,"align",exact=TRUE)[tmp.index.start] == '|' ) tmp.index.start <- tmp.index.start + 1\r
       tmp.index.start <- tmp.index.start + 1\r
     }\r
-    BTABULAR <- paste("\\begin{",tabular.environment,"}{",\r
-                      paste(c(attr(x, "align",exact=TRUE)[tmp.index.start:length(attr(x,"align",exact=TRUE))], "}\n"),\r
-                            sep="", collapse=""),\r
-                      sep="")\r
+       # Added "width" argument for use with "tabular*" or "tabularx" environments - CR, 7/2/12\r
+       if (is.null(width)){\r
+         WIDTH <-""\r
+       } else if (is.element(tabular.environment, c("tabular", "longtable"))){\r
+         warning("Ignoring 'width' argument.  The 'tabular' and 'longtable' environments do not support a width specification.  Use another environment such as 'tabular*' or 'tabularx' to specify the width.")\r
+         WIDTH <- ""\r
+       } else {\r
+         WIDTH <- paste("{", width, "}", sep="")\r
+       }\r
+       \r
+    BTABULAR <- paste("\\begin{",tabular.environment,"}", WIDTH, "{",\r
+        paste(c(attr(x, "align",exact=TRUE)[tmp.index.start:length(attr(x,"align",\r
+                   exact=TRUE))], "}\n"), sep="", collapse=""),\r
+        sep="")\r
 \r
     ## fix 10-26-09 (robert.castelo@upf.edu) the following 'if' condition is added here to support\r
     ## a caption on the top of a longtable\r