]> git.donarmstrong.com Git - xtable.git/blobdiff - pkg/vignettes/xtableGallery.Rnw
Added ability to produce mathematical arrays
[xtable.git] / pkg / vignettes / xtableGallery.Rnw
index 8491e129fb493da37ecfeccc5c2f894f2ae17561..4aa6d43f9fca060f2db4338efd7b767189e7110a 100644 (file)
@@ -7,6 +7,7 @@
 %**************************************************************************\r
 \documentclass{article}\r
 \usepackage[a4paper,height=24cm]{geometry} % geometry first\r
+\usepackage{listings}\r
 \usepackage{array}\r
 \usepackage{booktabs}\r
 \usepackage{longtable}\r
 \newcommand\code[1]{\texttt{#1}}\r
 \newcommand\pkg[1]{\textbf{#1}}\r
 \setcounter{tocdepth}{2}\r
+\r
+\lstset{language=R,basicstyle=\ttfamily,\r
+        keywordstyle=\ttfamily,\r
+        emphstyle=\itshape,\r
+        escapeinside = ||,\r
+        lineskip=0pt}\r
+\r
 \begin{document}\r
 \r
 \title{The \pkg{xtable} Gallery}\r
@@ -121,6 +129,36 @@ temp.table <- xtable(temp.ts, digits = 0)
 temp.table\r
 @\r
 \r
+\subsection{Mathematical arrays}\r
+\label{sec:mathematical-arrays}\r
+\r
+Mathematical arrays (as compared to data arrays) can be printed\r
+correctly by declaring the class as \code{xtableMatharray}.\r
+<<matharraydata>>=\r
+V <- matrix(c(1.140380e-03,  3.010497e-05,  7.334879e-05,\r
+              3.010497e-05,  3.320683e-04, -5.284854e-05,\r
+              7.334879e-05, -5.284854e-05,  3.520928e-04), nrow = 3)\r
+V\r
+class(V) <- c("xtableMatharray")\r
+class(V)\r
+xtbl <- print(xtable(V, display = rep("E", 4)))\r
+@ %def\r
+\r
+Then \code{xtbl} can be used in an expression such as\r
+$V=\left[\Sexpr{xtbl}\right]$, produced by\r
+\begin{lstlisting}\r
+V=\left[\Sexp||r{xtbl}\right]. \r
+\end{lstlisting}\r
+\r
+\r
+An alternative display can be created using the \texttt{digits}\r
+argument. If \code{xtbl} is defined instead according to\r
+\r
+<<altmatharray, results = 'hide'>>=\r
+xtbl <- print(xtable(V, digits = 6))\r
+@ %def \r
+then we get\\\r
+$V=\left[\Sexpr{paste(print(xtable(V, digits = 6)))}\right].$ \r
 \newpage\r
 \r
 <<include=FALSE>>=\r
@@ -209,6 +247,7 @@ print(wanttex, sanitize.text.function =
       function(str) gsub("_", "\\_", str, fixed = TRUE))\r
 @\r
 \r
+\r
 \newpage\r
 \r
 \subsection{Markup in tables}\r
@@ -237,6 +276,8 @@ money <- matrix(c("$1,000","$900","$100"), ncol = 3,
 print(xtable(money), sanitize.rownames.function = function(x) {x})\r
 @\r
 \r
+\r
+\r
 \section{Format examples}\r
 \subsection{Adding a centering environment}\r
 <<results='asis'>>=\r
@@ -291,6 +332,27 @@ digits(tli.table) <- matrix(0:4, nrow = 10, ncol = ncol(tli)+1)
 tli.table\r
 @\r
 \r
+\subsection{Minus signs}\r
+\label{sec:minus-signs}\r
+\r
+The standard print functions do not render minus signs properly. They\r
+are actually hyphens (-) rather than minus signs ($-$). True minus\r
+signs can be obtained using the \code{math.style.negative} argument.\r
+\r
+\p\r
+Here is the \LaTeX{} which is produced:\r
+\r
+<<>>=\r
+pr1 <- prcomp(USArrests)\r
+print(xtable(pr1), math.style.negative = TRUE)\r
+@ \r
+\r
+And here is the resulting table.\r
+<<results='asis'>>=\r
+print(xtable(pr1), math.style.negative = TRUE)\r
+@\r
+\r
+\r
 \newpage\r
 \r
 \subsection{Suppress row/column names}\r