From 9685304cf9b5f11473bfd511f668728339ee445d Mon Sep 17 00:00:00 2001
From: roosen <roosen@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Date: Mon, 30 Jan 2012 14:24:31 +0000
Subject: [PATCH] Added "short.caption" argument to "print.xtable()".  This was
 added to print.xtable rather than adding it to the xtable constructor to
 avoid making people rewrite their xtable methods.

git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@22 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
---
 pkg/NEWS                | 12 ++++++------
 pkg/R/print.xtable.R    | 13 +++++++++++--
 pkg/man/print.xtable.Rd |  4 +++-
 pkg/man/xtable.Rd       |  7 +++++++
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/pkg/NEWS b/pkg/NEWS
index 25520a5..d9b5d53 100644
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -1,16 +1,17 @@
 1.6-1 (NOT YET RELEASED)
-
   * Added some vectorization code to improve performance.
   * Added "toLatex" method.
-  * Included "print" in the exported methods in the NAMESPACE file.
   * Added "print.results" argument to "print" that can be used to
     suppress the printing.
+  * Added "format.args" argument to "print" that can be used to
+    pass additional arguments such as "big.marks" to "formatC()".
+  * Added "short.caption" argument to "print" to let the user 
+    specify a Latex short caption used when creating a list of tables. 
   * Added an "is.null()" check on the "table.placement" argument.
+  * Included "print.xtable" in the exported methods in the NAMESPACE file.
   * Added an example of header and footer specification with longtable
     to the vignette.  
-  * Added "format.args" argument to "print" that can be used to
-    pass additional arguments such as "big.marks" to "formatC()".
-
+	
 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.
@@ -30,4 +31,3 @@
   * Accommodated logicals by converting to characters.
   * Add an extra space at end of each line for LaTeX tables.
   * Fixed typographical error in documentation.
-
diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R
index aadbc62..a69f927 100644
--- a/pkg/R/print.xtable.R
+++ b/pkg/R/print.xtable.R
@@ -46,6 +46,7 @@ print.xtable <- function(
   html.table.attributes="border=1",
   print.results=TRUE,
   format.args=NULL,
+  short.caption=NULL,
   ...) {
   # Claudio Agostinelli <claudio@unive.it> dated 2006-07-28 hline.after
   # By default it print an \hline before and after the columns names independently they are printed or not and at the end of the table
@@ -171,7 +172,11 @@ print.xtable <- function(
     ## fix 10-26-09 (robert.castelo@upf.edu) the following 'if' condition is added here to support
     ## a caption on the top of a longtable
     if (tabular.environment == "longtable" && caption.placement=="top") {
-        BCAPTION <- "\\caption{"
+		if (is.null(short.caption)){
+			BCAPTION <- "\\caption{"
+		} else {
+			BCAPTION <- paste("\\caption[", short.caption, "]{", sep="")
+		}	
         ECAPTION <- "} \\\\ \n"
         if ((!is.null(attr(x,"caption",exact=TRUE))) && (type=="latex")) BTABULAR <- paste(BTABULAR,  BCAPTION, attr(x,"caption",exact=TRUE), ECAPTION, sep="")
     }
@@ -193,7 +198,11 @@ print.xtable <- function(
     }
     BLABEL <- "\\label{"
     ELABEL <- "}\n"
-    BCAPTION <- "\\caption{"
+	if (is.null(short.caption)){
+		BCAPTION <- "\\caption{"
+	} else {
+		BCAPTION <- paste("\\caption[", short.caption, "]{", sep="")
+	}	
     ECAPTION <- "}\n"
     BROW <- ""
     EROW <- " \\\\ \n"
diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd
index 5d1ffd5..fdf2df9 100644
--- a/pkg/man/print.xtable.Rd
+++ b/pkg/man/print.xtable.Rd
@@ -12,7 +12,8 @@
 		sanitize.colnames.function=sanitize.text.function, math.style.negative=FALSE, 
 		html.table.attributes="border=1", 
 		print.results=TRUE, 
-        format.args=NULL, ...)}
+        format.args=NULL, 
+		short.caption=NULL, ...)}
 \arguments{
   \item{x}{An object of class \code{"xtable"}.}
   \item{type}{Type of table to produce.  Possible values for \code{type} are \code{"latex"} or \code{"html"}.
@@ -47,6 +48,7 @@
   \item{html.table.attributes}{In an HTML table, attributes associated with the \code{<TABLE>} tag.  Default value is \code{border=1}.}
   \item{print.results}{If \code{TRUE}, the generated table is printed to standard output.  Set this to \code{FALSE} if you will just be using the character vector that is returned invisibly.}
   \item{format.args}{List of arguments for the \code{formatC} function.  For example, standard German number separators can be specified as \code{format.args=list(big.mark = "'", decimal.mark = ","))}.}
+  \item{short.caption}{A "short caption" can be specified that gets used as the table descriptor when LaTeX generates a "List of Tables".}
   \item{...}{Additional arguments.  (Currently ignored.)}
 }
 \details{
diff --git a/pkg/man/xtable.Rd b/pkg/man/xtable.Rd
index 60736f8..7211a83 100644
--- a/pkg/man/xtable.Rd
+++ b/pkg/man/xtable.Rd
@@ -196,6 +196,13 @@ print(xtable(anova(glm.D93)),hline.after=c(1),size="small")
 ## Demonstration of additional formatC() arguments.
 print(fm1.table, format.args=list(big.mark = "'", decimal.mark = ","))
 
+## Demonstration of short caption support.
+fm1sc <- aov(tlimth ~ sex + ethnicty + grade, data=tli)
+fm1sc.table <- xtable(fm1sc, 
+  caption="ANOVA Model with Predictors Sex, Ethnicity, and Grade")
+print(fm1sc.table,
+  short.caption="ANOVA: Sex, Ethnicity, Grade")
+
 ## Demonstration of longtable support.
 ## Remember to insert \usepackage{longtable} on your LaTeX preamble
 x <- matrix(rnorm(1000), ncol = 10)
-- 
2.39.5