]> git.donarmstrong.com Git - xtable.git/commitdiff
Added extra longtable example to xtable Gallery
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Wed, 13 Jan 2016 02:12:22 +0000 (02:12 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Wed, 13 Jan 2016 02:12:22 +0000 (02:12 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@92 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/vignettes/xtableGallery.Rnw

index 1349096ab6c1be2d729016bae8bf2f913ffd4162..1a5f72d46fac454db33df9f9b128aecf0c51446b 100644 (file)
@@ -38,6 +38,7 @@ regression check for the package.
 <<include=FALSE>>=\r
 library(knitr)\r
 opts_chunk$set(fig.path='figdir/fig', debug=TRUE, echo=TRUE)\r
+set.seed(1234)\r
 @\r
 \r
 The first step is to load the package and set an option for this document.\r
@@ -193,13 +194,12 @@ If you prefer $5 \times 10^5$ in your tables to 5e5, the
 \code{math.style.exponents} option to \code{print.xtable} is useful:\r
 \r
 <<results='asis'>>=\r
-print(xtable(data.frame(text=c("foo","bar"),\r
-                        googols=c(10e10,50e10),\r
-                        small=c(8e-24,7e-5),\r
-                        row.names=c("A","B")),\r
-             display=c("s","s","g","g")),\r
-      math.style.exponents=TRUE\r
-      )\r
+print(xtable(data.frame(text = c("foo","bar"),\r
+                        googols = c(10e10,50e10),\r
+                        small = c(8e-24,7e-5),\r
+                        row.names = c("A","B")),\r
+             display = c("s","s","g","g")),\r
+      math.style.exponents = TRUE)\r
 @ \r
 \r
 this option also supports the values \code{ensuremath} which uses\r
@@ -450,39 +450,22 @@ x.big <- xtable(x, caption = "A \\code{longtable} spanning several pages")
 print(x.big, hline.after=c(-1, 0), tabular.environment = "longtable")\r
 @\r
 \r
-%% The column name alignment is off in the following example.\r
-%% It needs some revision before exposing it. - CR, 7/2/2012\r
-%\r
-%% Tried to fix this and got some of the way, but \hlines are wrong\r
-%% and first column is too wide. - DJS 4/10/2014\r
-%% \subsubsection{Long tables with the header on each page}\r
-%% The \code{add.to.row} argument can be used to display the header\r
-%% for a long table on each page, and to add a "continued" footer\r
-%% on all pages except the last page.\r
-\r
-%% \newcommand{\head}[1]{\centercell{\bfseries#1}}\r
-\r
-%% <<results='asis'>>=\r
-%% x <- matrix(rnorm(1000), ncol = 10)\r
-%% hdr <-  paste(paste("\\multicolumn{1}{c}{",1:9,"} & ", collapse = ""),\r
-%%               "\\multicolumn{1}{c}{10}\\\\")\r
-%% addtorow <- list()\r
-%% addtorow$pos <- list()\r
-%% addtorow$pos[[1]] <- c(0)\r
-%% addtorow$command <- c(paste(\r
-%%     hdr,\r
-%%     "  \\hline \n",\r
-%%     "  \\endhead \n",\r
-%%     "  \\hline \n",\r
-%%     "  {\\footnotesize Continued on next page} \n",\r
-%%     "  \\endfoot \n",\r
-%%     "  \\endlastfoot \n", sep = ""))\r
-%% x.big2 <- xtable(x, label = "tabbig2", align = "lrrrrrrrrrr",\r
-%%                  caption = "Example of longtable with the header on each page")\r
-%% print(x.big2, tabular.environment = "longtable",\r
-%%       include.rownames = FALSE, include.colnames = FALSE,\r
-%%       add.to.row = addtorow)\r
-%% @\r
+Extra features of the \pkg{longtable} \LaTeX{} package can typically\r
+be activated using \code{add.to.row}, as shown below.\r
+\r
+<<results='asis'>>=\r
+add.to.row <- list(pos = list(0), command = NULL)\r
+command <- paste0("\\hline\n\\endhead\n",\r
+                  "\\hline\n",\r
+                  "\\multicolumn{", dim(x)[2] + 1, "}{l}",\r
+                  "{\\footnotesize Continued on next page}\n",\r
+                  "\\endfoot\n",\r
+                  "\\endlastfoot\n") \r
+add.to.row$command <- command\r
+print(x.big, hline.after=c(-1), add.to.row = add.to.row,\r
+      tabular.environment = "longtable")\r
+@\r
+\r
 \r
 \newpage\r
 \r