]> git.donarmstrong.com Git - xtable.git/commitdiff
Implemented request #2168 for the inclusion of margintable as a floating environment...
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Thu, 16 Aug 2012 13:29:14 +0000 (13:29 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Thu, 16 Aug 2012 13:29:14 +0000 (13:29 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@36 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/NEWS
pkg/R/print.xtable.R
pkg/inst/doc/margintable.Rnw [new file with mode: 0644]

index 1a7c96764a4babec8587a76967f11fd304a6f889..10a193a3e35a58ad98527193d4a6ee2601552f8f 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -3,6 +3,10 @@
   * Changed implementation of centering of tables. Instead of
     inserting a centred environment, now a \centering command is
     inserted. Response to request #2104.
+  * Implemented request #2168 which allows 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.
 
 1.7-0
   * Added some vectorization code to improve performance.
index 79c486cef98fbdc4d0911419c637f5845ab27385..80d2edd5c90216d2531469b2c43cd0c5029cc96f 100644 (file)
@@ -176,8 +176,15 @@ print.xtable <- function(x,
         stop("\"type\" must be in {\"latex\", \"html\"}")\r
     }\r
     if (!all(!is.na(match(floating.environment,\r
-                          c("table","table*","sidewaystable"))))) {\r
-        stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\"}")\r
+                          c("table","table*","sidewaystable",\r
+                            "margintable"))))) {\r
+        stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}")\r
+    }\r
+    if ((match(floating.environment,\r
+              c("table","table*","sidewaystable","margintable"))\r
+        == "margintable") & (!is.null(table.placement))) {\r
+        warning("margintable does not allow for table placement; setting table.placement to NULL")\r
+        table.placement <- NULL\r
     }\r
     if (!is.null(table.placement) &&\r
         !all(!is.na(match(unlist(strsplit(table.placement,  split = "")),\r
diff --git a/pkg/inst/doc/margintable.Rnw b/pkg/inst/doc/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