* Added "scalebox" argument to include a "\scalebox" clause around
the tabular environment with the specified value used as the
scaling factor.
+ * Added "width" argument to allow specification of the width
+ value in tabular environments such as "tabularx".
* 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
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
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
aString.Width <- c(aString.Width,thisWidth)
}
- alignAllowed <- c("l","r","p","c","|")
+ alignAllowed <- c("l","r","p","c","|","X")
if (any( !(aString.Align %in% alignAllowed))) {
warning("Nonstandard alignments in align string")
\usepackage{rotating}
\usepackage{longtable}
\usepackage{booktabs}
+\usepackage{tabularx}
%\usepackage{hyperref}
\begin{document}
print(x.rescale, scalebox=0.7)
@
+\subsection{Table Width}
+The {\tt tabularx} tabular environment provides more alignment options,
+and has a \code{width} argument to specify the table width.
+
+Remember to insert \verb|\usepackage{tabularx}| in your \LaTeX preamble.
+
+<<>>=
+df.width <- data.frame(
+ "label 1 with much more text than is needed" = c("item 1", "A"),
+ "label 2 is also very long" = c("item 2","B"),
+ "label 3" = c("item 3","C"),
+ "label 4" = c("item 4 but again with too much text","D"),
+ check.names = FALSE)
+
+x.width <- xtable(df.width,
+ caption="Using the 'tabularx' environment")
+align(x.width) <- "|l|X|X|l|X|"
+@
+
+<<results=tex>>=
+print(x.width, tabular.environment="tabularx",
+ width="\\textwidth")
+@
+
\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
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
\arguments{\r
\item{x}{An object of class \code{"xtable"}.}\r
\item{rotate.colnames}{If \code{TRUE}, the column names are displayed vertically in LaTeX.}\r
\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.}\r
\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.}\r
+ \item{width}{If not \code{NULL}, the specified value is included in parenthesis between the tabular environment \code{begin} tag and the alignment specification. This allows specification of the table width when using tabular environments such as \code{tabular*} and \code{tabularx}. Note that table width specification is not supported with the \code{tabular} or \code{longtable} environments.}\r
\item{...}{Additional arguments. (Currently ignored.)}\r
}\r
\details{\r