]> git.donarmstrong.com Git - xtable.git/commitdiff
Fixed #2309. Altered xtableGallery.snw to illustrate new functionality. Moved vignett...
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Wed, 8 Jan 2014 00:57:41 +0000 (00:57 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Wed, 8 Jan 2014 00:57:41 +0000 (00:57 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@43 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/DESCRIPTION
pkg/NEWS
pkg/R/print.xtable.R
pkg/inst/doc/margintable.Rnw [deleted file]
pkg/inst/doc/margintable.pdf [deleted file]
pkg/inst/doc/xtableGallery.pdf [deleted file]
pkg/inst/doc/xtableGallery.snw [deleted file]
pkg/vignettes/margintable.Rnw [new file with mode: 0644]
pkg/vignettes/xtableGallery.snw [new file with mode: 0644]

index 58354a30106532cf9163e4fa441e1bff721dbf1a..88f6e2306c644399a35dd2092d2909f3bc780284 100644 (file)
@@ -1,6 +1,6 @@
 Package: xtable
-Version: 1.7-2
-Date: 2013/08/28
+Version: 1.7-3
+Date: 2014/01/08
 Title: Export tables to LaTeX or HTML
 Author: David B. Dahl <dahl@stat.tamu.edu>
 Maintainer: Charles Roosen <statsci@gmail.com>
index 5dd0e4c8eab913d8efe2cb71e921913616943c7a..b2770a38c84ba3a3e0f2e41fe2bd2eb807f83b83 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -1,3 +1,8 @@
+1.7-3 (NOT YET RELEASED)
+  * Fixed booktabs bug (#2309), more of an enhancement really. Updated
+    xtableGallery.snw to illustrate the change.
+  * Moved vignettes from inst/doc to vignettes as now required by CRAN
+
 1.7-2 (NOT YET RELEASED)
   * Fixed HTML gsub bug (#2795)
   * Dealt with format.args bug (#4770). No code changes, but the
@@ -9,8 +14,8 @@
   * Changed implementation of centering of tables. Instead of
     inserting a centered environment, now a \centering command is
     inserted. (Req #2104)
-  * Allow for margin tables as possible with document class 
-    tufte-handout. An example of usage is found in the vignette 
+  * Allow for margin tables as possible with document class
+    tufte-handout. An example of usage is found in the vignette
        produced by margintable.Rnw which is in inst/doc. (Req #2168)
   * Added "timestamp" argument to print.xtable().  Set it to NULL
     if no timestamp is desired. (Req #2246)
     list of known floating environments. Users want to use floating
     environments from multiple options LaTeX packages (Req #2488,
     #2578)
-       
+
 1.7-0 (2012-02-10)
   * Added some vectorization code to improve performance.
-  * Let "caption" be length 2, in which case the second value is 
+  * Let "caption" be length 2, in which case the second value is
     the short caption used when creating a list of tables.
   * Added "toLatex" method.
   * Included "print.xtable" in the exported methods in the NAMESPACE file.
   * Added "format.args" argument to "print" that can be used to
     pass additional arguments such as "big.marks" to "formatC()".
   * Added "rotate.colnames" and "rotate.rownames" arguments to
-    "print.xtable".  
-  * Added "booktabs" argument to use the "\toprule", "\midrule", and  
+    "print.xtable".
+  * 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.    
+    scaling factor.
   * Added "width" argument to allow specification of the width
     value in tabular environments such as "tabularx".
   * Added "X" as an allowed alignment value in the "align()"
-    replacement function.  
+    replacement function.
   * 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 examples using the new arguments to the vignette.
-       
+
 1.6-0 (2011-10-07)
   * Allow "table*" as a value for "floating.environment" in print.xtable().
   * Fix bug under which multiple logical columns were formatted incorrectly.
index d057595376cc67e47925c7fe826550bb9d3284d3..34b0a7c43facb9f0089f189321a15b75a807b596 100644 (file)
@@ -127,20 +127,33 @@ print.xtable <- function(x,
         ## 1 Feb 2012\r
         if(!booktabs){\r
             PHEADER <- "\\hline\n"\r
-           } else {\r
-            PHEADER <- ifelse(-1%in%hline.after, "\\toprule\n", "")\r
-            if(0%in%hline.after) {\r
-                PHEADER <- c(PHEADER, "\\midrule\n")\r
-            }\r
-            if(nrow(x)%in%hline.after) {\r
-                PHEADER <- c(PHEADER, "\\bottomrule\n")\r
+        } else {\r
+            ## This code replaced to fix bug #2309, David Scott, 8 Jan 2014\r
+            ## PHEADER <- ifelse(-1%in%hline.after, "\\toprule\n", "")\r
+            ## if(0%in%hline.after) {\r
+            ##     PHEADER <- c(PHEADER, "\\midrule\n")\r
+            ## }\r
+            ## if(nrow(x)%in%hline.after) {\r
+            ##     PHEADER <- c(PHEADER, "\\bottomrule\n")\r
+            ## }\r
+            if (is.null(hline.after)){\r
+                PHEADER <- ""\r
+            } else {\r
+                hline.after <- sort(hline.after)\r
+                PHEADER <- rep("\\midrule\n", length(hline.after))\r
+                if (hline.after[1] == -1) {\r
+                    PHEADER[1] <- "\\toprule\n"\r
+                }\r
+                if (hline.after[length(hline.after)] == nrow(x)) {\r
+                    PHEADER[length(hline.after)] <- "\\bottomrule\n"\r
+                }\r
             }\r
         }\r
     } else {\r
         PHEADER <- ""\r
     }\r
 \r
-    lastcol <- rep(" ", nrow(x)+2)\r
+        lastcol <- rep(" ", nrow(x)+2)\r
     if (!is.null(hline.after)) {\r
         ## booktabs change - Matthieu Stigler: fill the hline arguments\r
         ## separately, 1 Feb 2012\r
diff --git a/pkg/inst/doc/margintable.Rnw b/pkg/inst/doc/margintable.Rnw
deleted file mode 100644 (file)
index b12c583..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-%\VignetteIndexEntry{xtable margintable}\r
-%\VignetteKeywords{LaTeX, HTML, table, margintable}\r
-\r
-\r
-\documentclass{tufte-handout}\r
-\r
-\r
-\title{\r
-A Margin Table Example\r
-}\r
-\author{David J. Scott}\r
-\r
-\usepackage{Sweave}\r
-\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}\r
-\usepackage{rotating}\r
-\usepackage{longtable}\r
-\usepackage{booktabs}\r
-\usepackage{tabularx}\r
-\usepackage{hyperref}\r
-\usepackage{fancyvrb}\r
-\fvset{fontsize=\normalsize}\r
-\r
-\begin{document}\r
-\r
-\section{The Example}\r
-\label{sec:example}\r
-\r
-This document uses the Tufte handout \LaTeX\ document style. This is\r
-specified by the use of the document class as\r
-\Verb|\documentclass{tufte-handout}|.\r
-\r
-The Tufte-\LaTeX\ document classes define a style similar to the\r
-style Edward Tufte uses in his books and handouts.  Tufte's style is known\r
-for its extensive use of sidenotes, tight integration of graphics with\r
-text, and well-set typography.\r
-\r
-One of the most prominent and distinctive features of this style is the\r
-extensive use of sidenotes.  There is a wide margin to provide ample room\r
-for sidenotes and small figures.  Any \Verb|\footnote|s will automatically\r
-be converted to sidenotes.\r
-\r
-Here is an example of a margin table, suggested by Felix Sch\"onbrodt\r
-\Verb|<nicebread@gmx.net>|. I am not sure about its usefullness in\r
-practice however. Note that \Verb|latex.environments = ""| avoids the\r
-default option of tables being centered, which in this example would\r
-lead to the caption not being directly under the table. Most\r
-importantly, \Verb|table.placement = NULL| is required to ensure that\r
-the default table placement options \Verb|[ht]| being inserted after\r
-\Verb|\begin{margintable}|. This is necessary because the margintable\r
-  environment does not allow placement options like \Verb|[ht]|.\r
-\r
-<<>>=\r
-library(xtable)\r
-x <- matrix(rnorm(6), ncol = 2)\r
-x.small <- xtable(x, label = 'tabsmall', caption = 'A margin table')\r
-@\r
-\r
-<<results=tex>>=\r
-print(x.small,floating.environment='margintable',\r
-      latex.environments = "",\r
-      table.placement = NULL)\r
-@\r
-\r
-\end{document}\r
diff --git a/pkg/inst/doc/margintable.pdf b/pkg/inst/doc/margintable.pdf
deleted file mode 100644 (file)
index 6644c4d..0000000
Binary files a/pkg/inst/doc/margintable.pdf and /dev/null differ
diff --git a/pkg/inst/doc/xtableGallery.pdf b/pkg/inst/doc/xtableGallery.pdf
deleted file mode 100644 (file)
index 029f97f..0000000
Binary files a/pkg/inst/doc/xtableGallery.pdf and /dev/null differ
diff --git a/pkg/inst/doc/xtableGallery.snw b/pkg/inst/doc/xtableGallery.snw
deleted file mode 100644 (file)
index 3994324..0000000
+++ /dev/null
@@ -1,552 +0,0 @@
-%\VignetteIndexEntry{xtable Gallery}
-%\VignetteDepends{xtable}
-%\VignetteKeywords{LaTeX,HTML,table}
-%\VignettePackage{xtable}
-
-%**************************************************************************
-%
-% # $Id:$
-
-% $Revision:  $
-% $Author: $
-% $Date:  $
-
-<<echo=FALSE,eval=FALSE>>=
-makeme <- function() {
-       # I am a convenience function for debugging and can be ignored
-       setwd("C:/JonathanSwinton/PathwayModeling/src/R/SourcePackages/xtable/inst/doc")
-       Sweave("xtableGallery.RnW",stylepath=FALSE)
-}
-makeme()
-@
-
-\documentclass[letterpaper]{article}
-
-\title{
-The xtable gallery
-}
-\author{Jonathan Swinton <jonathan@swintons.net>\\ with small contributions from others}
-
-\usepackage{Sweave}
-\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
-\usepackage{rotating} 
-\usepackage{longtable} 
-\usepackage{booktabs}
-\usepackage{tabularx}
-%\usepackage{hyperref}
-\begin{document}
-
-\maketitle
-\section{Summary}
-This document gives a gallery of tables which can be made 
-by using the {\tt xtable} package to create \LaTeX\ output.
-It doubles as a regression check for the package.
-
-<<>>=
-library(xtable)
-@
-
-\section{Gallery}
-\subsection{Data frame}
-Load example dataset
-<<>>=
-data(tli)
-
-## Demonstrate data.frame
-tli.table <- xtable(tli[1:10,])
-digits(tli.table)[c(2,6)] <- 0
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE)
-@
-
-\subsection{Matrix}
-<<>>=
-design.matrix <- model.matrix(~ sex*grade, data=tli[1:10,])
-design.table <- xtable(design.matrix)
-@
-<<results=tex>>=
-print(design.table,floating=FALSE)
-@
-
-\subsection{aov}
-<<>>=
-fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli)
-fm1.table <- xtable(fm1)
-@
-<<results=tex>>=
-print(fm1.table,floating=FALSE)
-@
-\subsection{lm}
-<<>>=
-fm2 <- lm(tlimth ~ sex*ethnicty, data=tli)
-fm2.table <- xtable(fm2)
-@
-<<results=tex>>=
-print(fm2.table,floating=FALSE)
-@
-\subsubsection{anova object}
-
-<<results=tex>>=
-print(xtable(anova(fm2)),floating=FALSE)
-@
-\subsubsection{Another anova object}
-<<>>=
-fm2b <- lm(tlimth ~ ethnicty, data=tli)
-@
-<<results=tex>>=
-print(xtable(anova(fm2b,fm2)),floating=FALSE)
-@
-
-
-\subsection{glm}
-
-<<>>=
-
-## Demonstrate glm
-fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial())
-fm3.table <- xtable(fm3)
-@
-<<results=tex>>=
-print(fm3.table,floating=FALSE)
-@
-
-\subsubsection{anova object}
-@
-<<results=tex>>=
-print(xtable(anova(fm3)),floating=FALSE)
-@
-
-
-\subsection{More aov}
-<<>>=
-
-## Demonstrate aov
-## Taken from help(aov) in R 1.1.1
-## From Venables and Ripley (1997) p.210.
-N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
-P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
-K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
-yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
-           62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
-npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P), K=factor(K), yield=yield)
-npk.aov <- aov(yield ~ block + N*P*K, npk)
-op <- options(contrasts=c("contr.helmert", "contr.treatment"))
-npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
-options(op)
-#summary(npk.aov)
-@
-<<results=tex>>=
-print(xtable(npk.aov),floating=FALSE)
-@
-
-\subsubsection{anova object}
-<<results=tex>>=
-print(xtable(anova(npk.aov)),floating=FALSE)
-@
-
-\subsubsection{Another anova object}
-<<results=tex>>=
-print(xtable(summary(npk.aov)),floating=FALSE)
-@
-
-<<>>=
-#summary(npk.aovE)
-@
-<<results=tex>>=
-print(xtable(npk.aovE),floating=FALSE)
-@
-
-
-<<results=tex>>=
-print(xtable(summary(npk.aovE)),floating=FALSE)
-@
-
-\subsection{More lm}
-<<>>=
-
-## Demonstrate lm
-## Taken from help(lm) in R 1.1.1
-## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
-## Page 9: Plant Weight Data.
-ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
-trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
-group <- gl(2,10,20, labels=c("Ctl","Trt"))
-weight <- c(ctl, trt)
-lm.D9 <- lm(weight ~ group)
-@
-<<results=tex>>=
-print(xtable(lm.D9),floating=FALSE)
-@
-
-
-<<results=tex>>=
-print(xtable(anova(lm.D9)),floating=FALSE)
-@
-
-\subsection{More glm}
-<<>>=
-
-## Demonstrate glm
-## Taken from help(glm) in R 1.1.1
-## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
-## Page 93: Randomized Controlled Trial :
-counts <- c(18,17,15,20,10,20,25,13,12)
-outcome <- gl(3,1,9)
-treatment <- gl(3,3)
-d.AD <- data.frame(treatment, outcome, counts)
-glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
-@
-<<results=tex>>=
-print(xtable(glm.D93,align="r|llrc"),floating=FALSE)
-@
-
-\subsection{prcomp}
-<<prcomp>>=
-if(require(stats,quietly=TRUE)) {
-  ## Demonstrate prcomp
-  ## Taken from help(prcomp) in mva package of R 1.1.1
-  data(USArrests)
-  pr1 <- prcomp(USArrests)
-}
-@
-<<results=tex>>=
-if(require(stats,quietly=TRUE)) {
-  print(xtable(pr1),floating=FALSE)
-}
-@
-
-
-@
-<<results=tex>>=
-  print(xtable(summary(pr1)),floating=FALSE)
-@
-
-
-
-<<>>=
-#  ## Demonstrate princomp
-#  ## Taken from help(princomp) in mva package of R 1.1.1
-#  pr2 <- princomp(USArrests)
-#  print(xtable(pr2))
-@
-\subsection{Time series}
-
-<<>>=
-temp.ts <- ts(cumsum(1+round(rnorm(100), 0)), start = c(1954, 7), frequency=12)
-   temp.table <- xtable(temp.ts,digits=0)
-    caption(temp.table) <- "Time series example"
-@
-<<results=tex>>=
-    print(temp.table,floating=FALSE)
-@
-<<savetofile,echo=FALSE>>=
-if (FALSE) {
-  for(i in c("latex","html")) {
-    outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="")
-    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments=NULL)
-    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="")
-    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="center")
-    print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE)
-    print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE)
-      # print(xtable(pr2),type=i,file=outFileName,append=TRUE)
-         }
-} 
-@
-
-\section{Sanitization}
-<<>>=
-insane <- data.frame(Name=c("Ampersand","Greater than","Less than","Underscore","Per cent","Dollar","Backslash","Hash", "Caret", "Tilde","Left brace","Right brace"),
-                               Character = I(c("&",">",                "<",            "_",            "%",            "$",            "\\", "#",      "^",            "~","{","}")))
-colnames(insane)[2] <- paste(insane[,2],collapse="")
-@
-
-<<pxti,results=tex>>=
-print( xtable(insane))
-@
-Sometimes you might want to have your own sanitization function
-<<>>=
-wanttex <- xtable(data.frame( label=paste("Value_is $10^{-",1:3,"}$",sep="")))
-@
-<<results=tex>>=
-print(wanttex,sanitize.text.function=function(str)gsub("_","\\_",str,fixed=TRUE))
-@
-
-\subsection{Markup in tables}
-
-Markup can be kept in tables, including column and row names, by using a custom sanitize.text.function:
-
-<<>>=
-mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
-rownames(mat) <- "$y_{t-1}$"
-colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")
-mat <- xtable(mat)
-@
-<<results=tex>>=
-print(mat, sanitize.text.function = function(x){x})
-@
-
-% By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.
-You can also have sanitize functions that are specific to column or row names.  In the table below, the row name is not sanitized but column names and table elements are:
-<<>>=
-money <- matrix(c("$1,000","$900","$100"),ncol=3,dimnames=list("$\\alpha$",c("Income (US$)","Expenses (US$)","Profit (US$)")))
-@
-<<results=tex>>=
-print(xtable(money),sanitize.rownames.function=function(x) {x})
-@
-
-\section{Format examples}
-\subsection{Adding a centering environment }
-<<results=tex>>=
-   print(xtable(lm.D9,caption="\\tt latex.environments=NULL"),latex.environments=NULL)
-    print(xtable(lm.D9,caption="\\tt latex.environments=\"\""),latex.environments="")
-    print(xtable(lm.D9,caption="\\tt latex.environments=\"center\""),latex.environments="center")
-@
-\subsection{Column alignment}
-
-<<>>=
-tli.table <- xtable(tli[1:10,])
-@
-<<>>=
-align(tli.table) <- rep("r",6)
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE)
-@
-\subsubsection{Single string and column lines}
-<<>>=
-align(tli.table) <- "|rrl|l|lr|"
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE)
-@
-\subsubsection{Fixed width columns}
-<<>>=
-align(tli.table) <- "|rr|lp{3cm}l|r|"
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE)
-@
-
-\subsection{Significant digits}
-
-
-Specify with a single argument 
-<<>>=
-digits(tli.table) <- 3
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE,)
-@
-
-
-or one for each column, counting the row names
-<<>>=
-digits(tli.table) <- 1:(ncol(tli)+1)
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE,)
-@
-
-
-or as a full matrix
-<<>>=
-digits(tli.table) <- matrix( 0:4, nrow = 10, ncol = ncol(tli)+1 )
-@
-<<results=tex>>=
-print(tli.table,floating=FALSE,)
-@
-
-\subsection{Suppress row names}
-<<results=tex>>=
-print((tli.table),include.rownames=FALSE,floating=FALSE)
-@
-
-If you want a vertical line on the left, you need to change the align attribute.
-<<>>=
-align(tli.table) <- "|r|r|lp{3cm}l|r|"
-@
-<<results=tex>>=
-print((tli.table),include.rownames=FALSE,floating=FALSE)
-@
-
-Revert the alignment to what is was before.
-<<>>=
-align(tli.table) <- "|rr|lp{3cm}l|r|"
-@
-
-\subsection{Suppress column names}
-<<results=tex>>=
-print((tli.table),include.colnames=FALSE,floating=FALSE)
-@
-\\
-Note the doubled header lines which can be suppressed with, eg,
-<<results=tex>>=
-print(tli.table,include.colnames=FALSE,floating=FALSE,hline.after=c(0,nrow(tli.table)))
-@
-
-\subsection{Suppress row and column names}
-<<results=tex>>=
-print((tli.table),include.colnames=FALSE,include.rownames=FALSE,floating=FALSE)
-@
-
-\subsection{Rotate row and column names}
-The {\tt rotate.rownames } and {\tt rotate.colnames} arguments can be
-used to rotate the row and/or column names.
-
-<<results=tex>>=
-print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE)
-@
-
-\subsection{Horizontal lines}
-
-\subsubsection{Line locations}
-
-Use the {\tt hline.after} argument to specify the position of the horizontal lines.
-
-<<results=tex>>=
-print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE)
-@
-
-\subsubsection{Line styles}
-
-The \LaTeX package {\tt booktabs} can be used to specify different 
-line style tags for top, middle, and bottom lines.  Specifying
-{\tt booktabs = TRUE} will lead to separate tags being generated
-for the three line types.
-
-Insert \verb|\usepackage{booktabs}| in your \LaTeX preamble and
-define the {\tt toprule}, {\tt midrule}, and {\tt bottomrule}
-tags to specify the line styles.
-
-<<results=tex>>=
-print(tli.table , booktabs=TRUE)
-@
-
-\subsection{Table-level \LaTeX}
-<<results=tex>>=
-print(xtable(anova(glm.D93)),size="small",floating=FALSE)
-@
-
-
-\subsection{Long tables}
-Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.
-
-<<longtable>>=
-
-## Demonstration of longtable support.
-x <- matrix(rnorm(1000), ncol = 10)
-x.big <- xtable(x,label='tabbig',
-       caption='Example of longtable spanning several pages')
-@
-<<results=tex>>=
-print(x.big,tabular.environment='longtable',floating=FALSE)
-@
-
-%%
-%% 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. 
-%
-%<<results=tex>>=
-%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.
-
-<<>>=
-x <- x[1:30,]
-x.small <- xtable(x,label='tabsmall',caption='A sideways table')
-@
-
-<<results=tex>>=
-print(x.small,floating.environment='sidewaystable')
-@
-\clearpage
-
-\subsection{Rescaled tables} 
-Specify a {\tt scalebox} value to rescale the table.
-
-<<>>=
-x <- x[1:20,]
-x.rescale <- xtable(x,label='tabrescaled',caption='A rescaled table')
-@
-
-<<results=tex>>=
-print(x.rescale, scalebox=0.7)
-@
-
-\subsection{Table Width} 
-The {\tt tabularx} tabular environment provides more alignment options,
-and has a {\tt 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
-standard output can be suppressed by specifying {\tt print.results = FALSE}.
-
-<<>>=
-x.out <- print(tli.table, print.results = FALSE)
-@
-
-Formatted output can also be captured without printing with the
-{\tt toLatex} method.  This function returns an object of class
-{\tt "Latex"}.
-
-<<>>=
-x.ltx <- toLatex(tli.table)
-class(x.ltx)
-x.ltx
-@
-
-\section{Acknowledgements}
-Most of the examples in this gallery are taken from the {\tt xtable} documentation.
-\section{R Session information}
-<<results=tex>>=
-toLatex(sessionInfo())
-@
-\end{document}
diff --git a/pkg/vignettes/margintable.Rnw b/pkg/vignettes/margintable.Rnw
new file mode 100644 (file)
index 0000000..b12c583
--- /dev/null
@@ -0,0 +1,64 @@
+%\VignetteIndexEntry{xtable margintable}\r
+%\VignetteKeywords{LaTeX, HTML, table, margintable}\r
+\r
+\r
+\documentclass{tufte-handout}\r
+\r
+\r
+\title{\r
+A Margin Table Example\r
+}\r
+\author{David J. Scott}\r
+\r
+\usepackage{Sweave}\r
+\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}\r
+\usepackage{rotating}\r
+\usepackage{longtable}\r
+\usepackage{booktabs}\r
+\usepackage{tabularx}\r
+\usepackage{hyperref}\r
+\usepackage{fancyvrb}\r
+\fvset{fontsize=\normalsize}\r
+\r
+\begin{document}\r
+\r
+\section{The Example}\r
+\label{sec:example}\r
+\r
+This document uses the Tufte handout \LaTeX\ document style. This is\r
+specified by the use of the document class as\r
+\Verb|\documentclass{tufte-handout}|.\r
+\r
+The Tufte-\LaTeX\ document classes define a style similar to the\r
+style Edward Tufte uses in his books and handouts.  Tufte's style is known\r
+for its extensive use of sidenotes, tight integration of graphics with\r
+text, and well-set typography.\r
+\r
+One of the most prominent and distinctive features of this style is the\r
+extensive use of sidenotes.  There is a wide margin to provide ample room\r
+for sidenotes and small figures.  Any \Verb|\footnote|s will automatically\r
+be converted to sidenotes.\r
+\r
+Here is an example of a margin table, suggested by Felix Sch\"onbrodt\r
+\Verb|<nicebread@gmx.net>|. I am not sure about its usefullness in\r
+practice however. Note that \Verb|latex.environments = ""| avoids the\r
+default option of tables being centered, which in this example would\r
+lead to the caption not being directly under the table. Most\r
+importantly, \Verb|table.placement = NULL| is required to ensure that\r
+the default table placement options \Verb|[ht]| being inserted after\r
+\Verb|\begin{margintable}|. This is necessary because the margintable\r
+  environment does not allow placement options like \Verb|[ht]|.\r
+\r
+<<>>=\r
+library(xtable)\r
+x <- matrix(rnorm(6), ncol = 2)\r
+x.small <- xtable(x, label = 'tabsmall', caption = 'A margin table')\r
+@\r
+\r
+<<results=tex>>=\r
+print(x.small,floating.environment='margintable',\r
+      latex.environments = "",\r
+      table.placement = NULL)\r
+@\r
+\r
+\end{document}\r
diff --git a/pkg/vignettes/xtableGallery.snw b/pkg/vignettes/xtableGallery.snw
new file mode 100644 (file)
index 0000000..2dfa32b
--- /dev/null
@@ -0,0 +1,585 @@
+%\VignetteIndexEntry{xtable Gallery}
+%\VignetteDepends{xtable}
+%\VignetteKeywords{LaTeX,HTML,table}
+%\VignettePackage{xtable}
+
+%**************************************************************************
+%
+% # $Id:$
+
+% $Revision:  $
+% $Author: $
+% $Date:  $
+
+<<echo=FALSE,eval=FALSE>>=
+makeme <- function() {
+       # I am a convenience function for debugging and can be ignored
+       setwd("C:/JonathanSwinton/PathwayModeling/src/R/SourcePackages/xtable/inst/doc")
+       Sweave("xtableGallery.RnW",stylepath=FALSE)
+}
+makeme()
+@
+
+\documentclass[letterpaper]{article}
+
+\title{
+The xtable gallery
+}
+\author{Jonathan Swinton <jonathan@swintons.net>\\ with small contributions from others}
+
+\usepackage{Sweave}
+\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE}
+\usepackage{rotating}
+\usepackage{longtable}
+\usepackage{booktabs}
+\usepackage{tabularx}
+%\usepackage{hyperref}
+\begin{document}
+
+\maketitle
+\section{Summary}
+This document gives a gallery of tables which can be made
+by using the {\tt xtable} package to create \LaTeX\ output.
+It doubles as a regression check for the package.
+
+<<>>=
+library(xtable)
+@
+
+\section{Gallery}
+\subsection{Data frame}
+Load example dataset
+<<>>=
+data(tli)
+
+## Demonstrate data.frame
+tli.table <- xtable(tli[1:10,])
+digits(tli.table)[c(2,6)] <- 0
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+
+\subsection{Matrix}
+<<>>=
+design.matrix <- model.matrix(~ sex*grade, data=tli[1:10,])
+design.table <- xtable(design.matrix)
+@
+<<results=tex>>=
+print(design.table,floating=FALSE)
+@
+
+\subsection{aov}
+<<>>=
+fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli)
+fm1.table <- xtable(fm1)
+@
+<<results=tex>>=
+print(fm1.table,floating=FALSE)
+@
+\subsection{lm}
+<<>>=
+fm2 <- lm(tlimth ~ sex*ethnicty, data=tli)
+fm2.table <- xtable(fm2)
+@
+<<results=tex>>=
+print(fm2.table,floating=FALSE)
+@
+\subsubsection{anova object}
+
+<<results=tex>>=
+print(xtable(anova(fm2)),floating=FALSE)
+@
+\subsubsection{Another anova object}
+<<>>=
+fm2b <- lm(tlimth ~ ethnicty, data=tli)
+@
+<<results=tex>>=
+print(xtable(anova(fm2b,fm2)),floating=FALSE)
+@
+
+
+\subsection{glm}
+
+<<>>=
+
+## Demonstrate glm
+fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial())
+fm3.table <- xtable(fm3)
+@
+<<results=tex>>=
+print(fm3.table,floating=FALSE)
+@
+
+\subsubsection{anova object}
+@
+<<results=tex>>=
+print(xtable(anova(fm3)),floating=FALSE)
+@
+
+
+\subsection{More aov}
+<<>>=
+
+## Demonstrate aov
+## Taken from help(aov) in R 1.1.1
+## From Venables and Ripley (1997) p.210.
+N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
+P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
+K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
+yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,
+           62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
+npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P), K=factor(K), yield=yield)
+npk.aov <- aov(yield ~ block + N*P*K, npk)
+op <- options(contrasts=c("contr.helmert", "contr.treatment"))
+npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)
+options(op)
+#summary(npk.aov)
+@
+<<results=tex>>=
+print(xtable(npk.aov),floating=FALSE)
+@
+
+\subsubsection{anova object}
+<<results=tex>>=
+print(xtable(anova(npk.aov)),floating=FALSE)
+@
+
+\subsubsection{Another anova object}
+<<results=tex>>=
+print(xtable(summary(npk.aov)),floating=FALSE)
+@
+
+<<>>=
+#summary(npk.aovE)
+@
+<<results=tex>>=
+print(xtable(npk.aovE),floating=FALSE)
+@
+
+
+<<results=tex>>=
+print(xtable(summary(npk.aovE)),floating=FALSE)
+@
+
+\subsection{More lm}
+<<>>=
+
+## Demonstrate lm
+## Taken from help(lm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 9: Plant Weight Data.
+ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
+trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
+group <- gl(2,10,20, labels=c("Ctl","Trt"))
+weight <- c(ctl, trt)
+lm.D9 <- lm(weight ~ group)
+@
+<<results=tex>>=
+print(xtable(lm.D9),floating=FALSE)
+@
+
+
+<<results=tex>>=
+print(xtable(anova(lm.D9)),floating=FALSE)
+@
+
+\subsection{More glm}
+<<>>=
+
+## Demonstrate glm
+## Taken from help(glm) in R 1.1.1
+## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
+## Page 93: Randomized Controlled Trial :
+counts <- c(18,17,15,20,10,20,25,13,12)
+outcome <- gl(3,1,9)
+treatment <- gl(3,3)
+d.AD <- data.frame(treatment, outcome, counts)
+glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
+@
+<<results=tex>>=
+print(xtable(glm.D93,align="r|llrc"),floating=FALSE)
+@
+
+\subsection{prcomp}
+<<prcomp>>=
+if(require(stats,quietly=TRUE)) {
+  ## Demonstrate prcomp
+  ## Taken from help(prcomp) in mva package of R 1.1.1
+  data(USArrests)
+  pr1 <- prcomp(USArrests)
+}
+@
+<<results=tex>>=
+if(require(stats,quietly=TRUE)) {
+  print(xtable(pr1),floating=FALSE)
+}
+@
+
+
+@
+<<results=tex>>=
+  print(xtable(summary(pr1)),floating=FALSE)
+@
+
+
+
+<<>>=
+#  ## Demonstrate princomp
+#  ## Taken from help(princomp) in mva package of R 1.1.1
+#  pr2 <- princomp(USArrests)
+#  print(xtable(pr2))
+@
+\subsection{Time series}
+
+<<>>=
+temp.ts <- ts(cumsum(1+round(rnorm(100), 0)), start = c(1954, 7), frequency=12)
+   temp.table <- xtable(temp.ts,digits=0)
+    caption(temp.table) <- "Time series example"
+@
+<<results=tex>>=
+    print(temp.table,floating=FALSE)
+@
+<<savetofile,echo=FALSE>>=
+if (FALSE) {
+  for(i in c("latex","html")) {
+    outFileName <- paste("xtable.",ifelse(i=="latex","tex",i),sep="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments=NULL)
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="")
+    print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environments="center")
+    print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE)
+    print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE)
+      # print(xtable(pr2),type=i,file=outFileName,append=TRUE)
+         }
+}
+@
+
+\section{Sanitization}
+<<>>=
+insane <- data.frame(Name=c("Ampersand","Greater than","Less than","Underscore","Per cent","Dollar","Backslash","Hash", "Caret", "Tilde","Left brace","Right brace"),
+                               Character = I(c("&",">",                "<",            "_",            "%",            "$",            "\\", "#",      "^",            "~","{","}")))
+colnames(insane)[2] <- paste(insane[,2],collapse="")
+@
+
+<<pxti,results=tex>>=
+print( xtable(insane))
+@
+Sometimes you might want to have your own sanitization function
+<<>>=
+wanttex <- xtable(data.frame( label=paste("Value_is $10^{-",1:3,"}$",sep="")))
+@
+<<results=tex>>=
+print(wanttex,sanitize.text.function=function(str)gsub("_","\\_",str,fixed=TRUE))
+@
+
+\subsection{Markup in tables}
+
+Markup can be kept in tables, including column and row names, by using a custom sanitize.text.function:
+
+<<>>=
+mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
+rownames(mat) <- "$y_{t-1}$"
+colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")
+mat <- xtable(mat)
+@
+<<results=tex>>=
+print(mat, sanitize.text.function = function(x){x})
+@
+
+% By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.
+You can also have sanitize functions that are specific to column or row names.  In the table below, the row name is not sanitized but column names and table elements are:
+<<>>=
+money <- matrix(c("$1,000","$900","$100"),ncol=3,dimnames=list("$\\alpha$",c("Income (US$)","Expenses (US$)","Profit (US$)")))
+@
+<<results=tex>>=
+print(xtable(money),sanitize.rownames.function=function(x) {x})
+@
+
+\section{Format examples}
+\subsection{Adding a centering environment }
+<<results=tex>>=
+   print(xtable(lm.D9,caption="\\tt latex.environments=NULL"),latex.environments=NULL)
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"\""),latex.environments="")
+    print(xtable(lm.D9,caption="\\tt latex.environments=\"center\""),latex.environments="center")
+@
+\subsection{Column alignment}
+
+<<>>=
+tli.table <- xtable(tli[1:10,])
+@
+<<>>=
+align(tli.table) <- rep("r",6)
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+\subsubsection{Single string and column lines}
+<<>>=
+align(tli.table) <- "|rrl|l|lr|"
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+\subsubsection{Fixed width columns}
+<<>>=
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE)
+@
+
+\subsection{Significant digits}
+
+
+Specify with a single argument
+<<>>=
+digits(tli.table) <- 3
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+
+or one for each column, counting the row names
+<<>>=
+digits(tli.table) <- 1:(ncol(tli)+1)
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+
+or as a full matrix
+<<>>=
+digits(tli.table) <- matrix( 0:4, nrow = 10, ncol = ncol(tli)+1 )
+@
+<<results=tex>>=
+print(tli.table,floating=FALSE,)
+@
+
+\subsection{Suppress row names}
+<<results=tex>>=
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+@
+
+If you want a vertical line on the left, you need to change the align attribute.
+<<>>=
+align(tli.table) <- "|r|r|lp{3cm}l|r|"
+@
+<<results=tex>>=
+print((tli.table),include.rownames=FALSE,floating=FALSE)
+@
+
+Revert the alignment to what is was before.
+<<>>=
+align(tli.table) <- "|rr|lp{3cm}l|r|"
+@
+
+\subsection{Suppress column names}
+<<results=tex>>=
+print((tli.table),include.colnames=FALSE,floating=FALSE)
+@
+\\
+Note the doubled header lines which can be suppressed with, eg,
+<<results=tex>>=
+print(tli.table,include.colnames=FALSE,floating=FALSE,hline.after=c(0,nrow(tli.table)))
+@
+
+\subsection{Suppress row and column names}
+<<results=tex>>=
+print((tli.table),include.colnames=FALSE,include.rownames=FALSE,floating=FALSE)
+@
+
+\subsection{Rotate row and column names}
+The {\tt rotate.rownames } and {\tt rotate.colnames} arguments can be
+used to rotate the row and/or column names.
+
+<<results=tex>>=
+print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE)
+@
+
+\subsection{Horizontal lines}
+
+\subsubsection{Line locations}
+
+Use the {\tt hline.after} argument to specify the position of the horizontal lines.
+
+<<results=tex>>=
+print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE)
+@
+
+\subsubsection{Line styles}
+
+The \LaTeX package {\tt booktabs} can be used to specify different
+line style tags for top, middle, and bottom lines.  Specifying
+{\tt booktabs = TRUE} will lead to separate tags being generated
+for the three line types.
+
+Insert \verb|\usepackage{booktabs}| in your \LaTeX preamble and define
+the {\tt toprule}, {\tt midrule}, and {\tt bottomrule} tags to specify
+the line styles. By default, when no value is given for
+\texttt{hline.after}, a \texttt{toprule} will be drawn above the
+table, a \texttt{midrule} after the table headings and a
+\texttt{bottomrule} below the table. The width of the top and bottom
+rules can be set by supplying a value to \verb+\heavyrulewidth+. The
+width of the midrules can be set by supplying a value to
+\verb+\lightrulewidth+. The following tables have
+\verb+\heavyrulewidth = 2pt+ and \verb+\lightrulewidth = 0.5pt+, to
+ensure the difference in weight is noticeable.
+
+There is no support for \verb+\cmidrule+ or \verb+\specialrule+
+although they are part of the \texttt{booktabs} package.
+
+\heavyrulewidth = 2pt
+\lightrulewidth = 0.5pt
+
+<<results=tex>>=
+print(tli.table, booktabs=TRUE, floating = FALSE)
+@
+
+\vspace{12pt}
+If \texttt{hline.after} includes $-1$, a \texttt{toprule} will be
+drawn above the table. If \texttt{hline.after} includes the number of
+rows in the table, a \texttt{bottomrule} will be drawn below the
+table. For any other values specified in \texttt{hline.after}, a
+\texttt{midrule} will be drawn after that line of the table.
+
+The next table has more than one \texttt{midrule}.
+
+<<>>=
+bktbs <- xtable(matrix(1:10, ncol = 2))
+hlines <- c(-1,0,1,nrow(bktbs))
+@
+This command produces the required table.
+<<results=tex>>=
+print(bktbs, booktabs = TRUE, hline.after = hlines, floating = FALSE)
+@
+
+
+\subsection{Table-level \LaTeX}
+<<results=tex>>=
+print(xtable(anova(glm.D93)),size="small",floating=FALSE)
+@
+
+
+\subsection{Long tables}
+Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.
+
+<<longtable>>=
+
+## Demonstration of longtable support.
+x <- matrix(rnorm(1000), ncol = 10)
+x.big <- xtable(x,label='tabbig',
+       caption='Example of longtable spanning several pages')
+@
+<<results=tex>>=
+print(x.big,tabular.environment='longtable',floating=FALSE)
+@
+
+%%
+%% 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.
+%
+%<<results=tex>>=
+%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.
+
+<<>>=
+x <- x[1:30,]
+x.small <- xtable(x,label='tabsmall',caption='A sideways table')
+@
+
+<<results=tex>>=
+print(x.small,floating.environment='sidewaystable')
+@
+\clearpage
+
+\subsection{Rescaled tables}
+Specify a {\tt scalebox} value to rescale the table.
+
+<<>>=
+x <- x[1:20,]
+x.rescale <- xtable(x,label='tabrescaled',caption='A rescaled table')
+@
+
+<<results=tex>>=
+print(x.rescale, scalebox=0.7)
+@
+
+\subsection{Table Width}
+The {\tt tabularx} tabular environment provides more alignment options,
+and has a {\tt 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
+standard output can be suppressed by specifying {\tt print.results = FALSE}.
+
+<<>>=
+x.out <- print(tli.table, print.results = FALSE)
+@
+
+Formatted output can also be captured without printing with the
+{\tt toLatex} method.  This function returns an object of class
+{\tt "Latex"}.
+
+<<>>=
+x.ltx <- toLatex(tli.table)
+class(x.ltx)
+x.ltx
+@
+
+\section{Acknowledgements}
+Most of the examples in this gallery are taken from the {\tt xtable} documentation.
+\section{R Session information}
+<<results=tex>>=
+toLatex(sessionInfo())
+@
+\end{document}