%**************************************************************************\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
<<results='asis'>>=\r
library(xtable)\r
options(xtable.floating = FALSE)\r
+options(xtable.timestamp = "")\r
@\r
\r
\section{Gallery}\r
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
\p\r
Sometimes you might want to have your own sanitization function.\r
\r
+\r
<<results='asis'>>=\r
wanttex <- xtable(data.frame(Column =\r
paste("Value_is $10^{-",1:3,"}$", sep = "")))\r
function(str) gsub("_", "\\_", str, fixed = TRUE))\r
@\r
\r
+\p\r
+Sanitization can be useful in formatting column headings and row names:\r
+\r
+<<sanitize3>>=\r
+dat <- mtcars[1:3, 1:6]\r
+large <- function(x){\r
+ paste0('{\\Large{\\bfseries ', x, '}}')\r
+}\r
+italic <- function(x){\r
+ paste0('{\\emph{ ', x, '}}')\r
+}\r
+@ %def\r
+\r
+<<sanitize4, results = 'asis'>>=\r
+print(xtable(dat),\r
+ sanitize.rownames.function = italic,\r
+ sanitize.colnames.function = large,\r
+ booktabs = TRUE)\r
+@ %def\r
+\r
+\r
\r
\newpage\r
\r
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
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