From: dscott Date: Thu, 16 Aug 2012 13:29:14 +0000 (+0000) Subject: Implemented request #2168 for the inclusion of margintable as a floating environment... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=93d6e73e18f821c50ce13b139ed554262dd27faa;p=xtable.git Implemented request #2168 for the inclusion of margintable as a floating environment. An example is given in margintable.Rnw in inst/doc which is the source for a new vignette. git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@36 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- diff --git a/pkg/NEWS b/pkg/NEWS index 1a7c967..10a193a 100644 --- 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. diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R index 79c486c..80d2edd 100644 --- a/pkg/R/print.xtable.R +++ b/pkg/R/print.xtable.R @@ -176,8 +176,15 @@ print.xtable <- function(x, stop("\"type\" must be in {\"latex\", \"html\"}") } if (!all(!is.na(match(floating.environment, - c("table","table*","sidewaystable"))))) { - stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\"}") + c("table","table*","sidewaystable", + "margintable"))))) { + stop("\"type\" must be in {\"table\", \"table*\", \"sidewaystable\", \"margintable\"}") + } + if ((match(floating.environment, + c("table","table*","sidewaystable","margintable")) + == "margintable") & (!is.null(table.placement))) { + warning("margintable does not allow for table placement; setting table.placement to NULL") + table.placement <- NULL } if (!is.null(table.placement) && !all(!is.na(match(unlist(strsplit(table.placement, split = "")), diff --git a/pkg/inst/doc/margintable.Rnw b/pkg/inst/doc/margintable.Rnw new file mode 100644 index 0000000..b12c583 --- /dev/null +++ b/pkg/inst/doc/margintable.Rnw @@ -0,0 +1,64 @@ +%\VignetteIndexEntry{xtable margintable} +%\VignetteKeywords{LaTeX, HTML, table, margintable} + + +\documentclass{tufte-handout} + + +\title{ +A Margin Table Example +} +\author{David J. Scott} + +\usepackage{Sweave} +\SweaveOpts{prefix.string=figdir/fig,debug=TRUE,eps=FALSE,echo=TRUE} +\usepackage{rotating} +\usepackage{longtable} +\usepackage{booktabs} +\usepackage{tabularx} +\usepackage{hyperref} +\usepackage{fancyvrb} +\fvset{fontsize=\normalsize} + +\begin{document} + +\section{The Example} +\label{sec:example} + +This document uses the Tufte handout \LaTeX\ document style. This is +specified by the use of the document class as +\Verb|\documentclass{tufte-handout}|. + +The Tufte-\LaTeX\ document classes define a style similar to the +style Edward Tufte uses in his books and handouts. Tufte's style is known +for its extensive use of sidenotes, tight integration of graphics with +text, and well-set typography. + +One of the most prominent and distinctive features of this style is the +extensive use of sidenotes. There is a wide margin to provide ample room +for sidenotes and small figures. Any \Verb|\footnote|s will automatically +be converted to sidenotes. + +Here is an example of a margin table, suggested by Felix Sch\"onbrodt +\Verb||. I am not sure about its usefullness in +practice however. Note that \Verb|latex.environments = ""| avoids the +default option of tables being centered, which in this example would +lead to the caption not being directly under the table. Most +importantly, \Verb|table.placement = NULL| is required to ensure that +the default table placement options \Verb|[ht]| being inserted after +\Verb|\begin{margintable}|. This is necessary because the margintable + environment does not allow placement options like \Verb|[ht]|. + +<<>>= +library(xtable) +x <- matrix(rnorm(6), ncol = 2) +x.small <- xtable(x, label = 'tabsmall', caption = 'A margin table') +@ + +<>= +print(x.small,floating.environment='margintable', + latex.environments = "", + table.placement = NULL) +@ + +\end{document}