]> git.donarmstrong.com Git - xtable.git/blob - pkg/vignettes/xtableGallery.Rnw
Whitespace commit, mainly vertical near the beginning, no change in PDF
[xtable.git] / pkg / vignettes / xtableGallery.Rnw
1 %\VignetteIndexEntry{xtable Gallery}\r
2 %\VignetteDepends{xtable}\r
3 %\VignetteKeywords{LaTeX, HTML, table}\r
4 %\VignettePackage{xtable}\r
5 % !Rnw weave = knitr\r
6 % \VignetteEngine{knitr::knitr}\r
7 %**************************************************************************\r
8 \documentclass[article, nojss]{jss}\r
9 \usepackage{amsthm}\r
10 \usepackage{amsmath}\r
11 \usepackage{graphicx}\r
12 \usepackage{color}\r
13 \usepackage{afterpage}\r
14 \usepackage{hyperref}\r
15 \r
16 \title{The \pkg{xtable} Gallery}\r
17 \author{Jonathan Swinton and others\\<jonathan@swintons.net>}\r
18 \Plainauthor{Jonathan Swinton, and others} %% comma-separated\r
19 \Plaintitle{The xtable Gallery} %% without formatting\r
20 \Shorttitle{\pkg{xtable} Gallery} %% a short title (if necessary)\r
21 \r
22 <<include=FALSE>>=\r
23 library(knitr)\r
24 opts_chunk$set(fig.path='figdir/fig', debug=TRUE, echo=TRUE)\r
25 options(replace.assign = TRUE, width = 60,\r
26         tidy.opts = list(width.cutoff = 60))\r
27 @\r
28 \r
29 \usepackage{rotating}\r
30 \usepackage{longtable}\r
31 \usepackage{booktabs}\r
32 \usepackage{tabularx}\r
33 %\usepackage{hyperref}\r
34 \r
35 \Abstract{\r
36   This document gives a gallery of tables which can be made by using\r
37   the \texttt{xtable} package to create \LaTeX\ output.  It doubles as\r
38   a regression check for the package.\r
39 }\r
40 \r
41 \Keywords{Reproducible research, \LaTeX}\r
42 \Address{Jonathan Swinton\\E-mail: \email{jonathan@swintons.net}}\r
43 \r
44 \begin{document}\r
45 \r
46 \section{Gallery}\r
47 \r
48 \subsection{Data frame}\r
49 Load example dataset\r
50 <<>>=\r
51 library(xtable)\r
52 options(xtable.floating = FALSE)\r
53 data(tli)\r
54 \r
55 ## Demonstrate data.frame\r
56 tli.table <- xtable(tli[1:10, ])\r
57 digits(tli.table)[c(2,6)] <- 0\r
58 @\r
59 <<results='asis'>>=\r
60 tli.table\r
61 @\r
62 \r
63 \newpage\r
64 \r
65 \subsection{Matrix}\r
66 <<>>=\r
67 design.matrix <- model.matrix(~ sex*grade, data = tli[1:10, ])\r
68 design.table <- xtable(design.matrix)\r
69 @\r
70 <<results='asis'>>=\r
71 design.table\r
72 @\r
73 \r
74 \subsection{aov}\r
75 <<>>=\r
76 fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)\r
77 fm1.table <- xtable(fm1)\r
78 @\r
79 <<results='asis'>>=\r
80 fm1.table\r
81 @\r
82 \r
83 \subsection{lm}\r
84 <<>>=\r
85 fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)\r
86 fm2.table <- xtable(fm2)\r
87 @\r
88 <<results='asis'>>=\r
89 fm2.table\r
90 @\r
91 \r
92 \vspace{12pt}\textbf{\itshape An anova object}\r
93 \r
94 <<results='asis'>>=\r
95 xtable(anova(fm2))\r
96 @\r
97 \vspace{12pt}\textbf{\itshape Another anova object}\r
98 <<>>=\r
99 fm2b <- lm(tlimth ~ ethnicty, data = tli)\r
100 @\r
101 <<results='asis'>>=\r
102 xtable(anova(fm2b, fm2))\r
103 @\r
104 \r
105 \subsection{glm}\r
106 <<>>=\r
107 ## Demonstrate glm\r
108 fm3 <- glm(disadvg ~ ethnicty*grade, data = tli, family = binomial())\r
109 fm3.table <- xtable(fm3)\r
110 @\r
111 <<results='asis'>>=\r
112 fm3.table\r
113 @\r
114 \r
115 \vspace{12pt}\textbf{\itshape An anova object}\r
116 <<results='asis'>>=\r
117 xtable(anova(fm3))\r
118 @\r
119 \r
120 \subsection{More aov}\r
121 <<>>=\r
122 ## Demonstrate aov\r
123 ## Taken from help(aov) in R 1.1.1\r
124 ## From Venables and Ripley (1997) p.210.\r
125 N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)\r
126 P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)\r
127 K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)\r
128 yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0,\r
129            62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)\r
130 npk <- data.frame(block = gl(6,4), N = factor(N), P = factor(P),\r
131                   K = factor(K), yield = yield)\r
132 npk.aov <- aov(yield ~ block + N*P*K, npk)\r
133 op <- options(contrasts = c("contr.helmert", "contr.treatment"))\r
134 npk.aovE <- aov(yield ~  N*P*K + Error(block), npk)\r
135 options(op)\r
136 @\r
137 <<results='asis'>>=\r
138 xtable(npk.aov)\r
139 @\r
140 \r
141 \vspace{12pt}\textbf{\itshape An anova object}\r
142 <<results='asis'>>=\r
143 xtable(anova(npk.aov))\r
144 @\r
145 \r
146 \vspace{12pt}\textbf{\itshape Another anova object}\r
147 <<results='asis'>>=\r
148 xtable(summary(npk.aov))\r
149 @\r
150 \r
151 <<results='asis'>>=\r
152 xtable(npk.aovE)\r
153 @\r
154 \r
155 <<results='asis'>>=\r
156 xtable(summary(npk.aovE))\r
157 @\r
158 \r
159 \subsection{More lm}\r
160 <<>>=\r
161 ## Demonstrate lm\r
162 ## Taken from help(lm) in R 1.1.1\r
163 ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".\r
164 ## Page 9: Plant Weight Data.\r
165 ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)\r
166 trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)\r
167 group <- gl(2,10,20, labels = c("Ctl","Trt"))\r
168 weight <- c(ctl, trt)\r
169 lm.D9 <- lm(weight ~ group)\r
170 @\r
171 <<results='asis'>>=\r
172 xtable(lm.D9)\r
173 @\r
174 \r
175 <<results='asis'>>=\r
176 xtable(anova(lm.D9))\r
177 @\r
178 \r
179 \subsection{More glm}\r
180 <<>>=\r
181 ## Demonstrate glm\r
182 ## Taken from help(glm) in R 1.1.1\r
183 ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".\r
184 ## Page 93: Randomized Controlled Trial :\r
185 counts <- c(18,17,15,20,10,20,25,13,12)\r
186 outcome <- gl(3,1,9)\r
187 treatment <- gl(3,3)\r
188 d.AD <- data.frame(treatment, outcome, counts)\r
189 glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())\r
190 @\r
191 <<results='asis'>>=\r
192 xtable(glm.D93, align = "r|llrc")\r
193 @\r
194 \r
195 \subsection{prcomp}\r
196 <<prcomp>>=\r
197 if(require(stats, quietly = TRUE)) {\r
198   ## Demonstrate prcomp\r
199   ## Taken from help(prcomp) in mva package of R 1.1.1\r
200   data(USArrests)\r
201   pr1 <- prcomp(USArrests)\r
202 }\r
203 @\r
204 <<results='asis'>>=\r
205 xtable(pr1)\r
206 @\r
207 \r
208 <<results='asis'>>=\r
209 xtable(summary(pr1))\r
210 @\r
211 \r
212 <<echo = FALSE, results = 'Hide'>>=\r
213 #  ## Demonstrate princomp\r
214 #  ## Taken from help(princomp) in mva package of R 1.1.1\r
215 #  pr2 <- princomp(USArrests)\r
216 #  xtable(pr2)\r
217 @\r
218 \r
219 \subsection{Time series}\r
220 <<>>=\r
221 temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)),\r
222               start = c(1954, 7), frequency = 12)\r
223 temp.table <- xtable(temp.ts, digits = 0)\r
224 caption(temp.table) <- "Time series example"\r
225 @\r
226 <<results='asis'>>=\r
227 temp.table\r
228 @\r
229 <<savetofile,echo=FALSE>>=\r
230 if (FALSE) {\r
231     for(i in c("latex", "html")) {\r
232         outFileName <- paste("xtable.", ifelse(i=="latex", "tex", i), sep = "")\r
233         print(xtable(lm.D9), type = i, file = outFileName, append = TRUE,\r
234               latex.environments = NULL)\r
235         print(xtable(lm.D9), type = i, file = outFileName, append = TRUE,\r
236               latex.environments = "")\r
237         print(xtable(lm.D9), type = i, file = outFileName, append = TRUE,\r
238               latex.environments = "center")\r
239         print(xtable(anova(glm.D93, test = "Chisq")),\r
240               type = i, file = outFileName,\r
241               append = TRUE)\r
242         print(xtable(anova(glm.D93)), hline.after = c(1),\r
243               size = "small", type = i,\r
244               file = outFileName, append = TRUE)\r
245       # print(xtable(pr2), type = i, file = outFileName, append = TRUE)\r
246     }\r
247 }\r
248 @\r
249 \r
250 \section{Helper functions for formatting}\r
251 \label{sec:helperfns}\r
252 The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are\r
253 useful for formatting tables in a sensible way.\r
254 \r
255 <<preliminary>>=\r
256 dat <- mtcars[1:3, 1:6]\r
257 @ %def\r
258 \r
259 Consider the output produced by the default formatting.\r
260 \r
261 <<current>>=\r
262 x <- xtable(dat)\r
263 x\r
264 @ %def\r
265 \r
266 In a \LaTeX\ document this appears as follows.\r
267 \r
268 <<currentresult, echo = FALSE, results = 'asis'>>=\r
269 x\r
270 @ %def\r
271 \r
272 Now change the default alignment, digits and display using helper functions\r
273 \texttt{xalign}, \texttt{xdigits}, and \texttt{xdisplay}.\r
274 \r
275 <<proposed>>=\r
276 align(x) <- xalign(x)\r
277 digits(x) <- xdigits(x)\r
278 display(x) <- xdisplay(x)\r
279 x\r
280 @ %def\r
281 \r
282 This produces a better format as shown below.\r
283 \r
284 <<proposedresult, echo = FALSE, results = 'asis'>>=\r
285 x\r
286 @ %def\r
287 \r
288 \section{Sanitization}\r
289 <<>>=\r
290 insane <- data.frame(Name = c("Ampersand","Greater than","Less than",\r
291                             "Underscore","Per cent","Dollar",\r
292                             "Backslash","Hash","Caret","Tilde",\r
293                             "Left brace","Right brace"),\r
294                      Character = I(c("&",">","<","_","%","$",\r
295                                      "\\","#","^","~","{","}")))\r
296 colnames(insane)[2] <- paste(insane[, 2], collapse = "")\r
297 @\r
298 \r
299 <<pxti,results='asis'>>=\r
300 xtable(insane)\r
301 @\r
302 \r
303 \vspace{12pt}\r
304 Sometimes you might want to have your own sanitization function\r
305 <<>>=\r
306 wanttex <- xtable(data.frame(label =\r
307                              paste("Value_is $10^{-",1:3,"}$", sep = "")))\r
308 @\r
309 <<results='asis'>>=\r
310 print(wanttex,\r
311       sanitize.text.function =\r
312       function(str)gsub("_", "\\_", str, fixed = TRUE))\r
313 @\r
314 \r
315 \subsection{Markup in tables}\r
316 Markup can be included in tables, including in column and row names, by using\r
317 a custom \code{sanitize.text.function()}:\r
318 \r
319 <<>>=\r
320 mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)\r
321 rownames(mat) <- "$y_{t-1}$"\r
322 colnames(mat) <- c("$R^2$", "$\\bar{R}^2$", "F-stat", "S.E.E", "DW")\r
323 mat <- xtable(mat)\r
324 @\r
325 <<results='asis'>>=\r
326 print(mat, sanitize.text.function = function(x){x})\r
327 @\r
328 \r
329 % By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.\r
330 You can also have sanitize functions that are specific to column or\r
331 row names.  In the table below, the row name is not sanitized but\r
332 column names and table elements are:\r
333 <<>>=\r
334 money <- matrix(c("$1,000","$900","$100"), ncol = 3,\r
335                 dimnames = list("$\\alpha$",\r
336                               c("Income (US$)","Expenses (US$)",\r
337                                 "Profit (US$)")))\r
338 @\r
339 <<results='asis'>>=\r
340 print(xtable(money), sanitize.rownames.function = function(x) {x})\r
341 @\r
342 \r
343 \section{Format examples}\r
344 \r
345 \subsection{Adding a centering environment }\r
346 <<results='asis'>>=\r
347    print(xtable(lm.D9, caption = "\\tt latex.environments = NULL"),\r
348          latex.environments = NULL)\r
349     print(xtable(lm.D9, caption = "\\tt latex.environments = \"\""),\r
350           latex.environments = "")\r
351     print(xtable(lm.D9, caption = "\\tt latex.environments = \"center\""),\r
352           latex.environments = "center")\r
353 @\r
354 \r
355 \subsection{Column alignment}\r
356 <<>>=\r
357 tli.table <- xtable(tli[1:10, ])\r
358 @\r
359 <<>>=\r
360 align(tli.table) <- rep("r", 6)\r
361 @\r
362 <<results='asis'>>=\r
363 tli.table\r
364 @\r
365 \r
366 \vspace{12pt}\r
367 \textbf{\itshape Single string and column lines}\r
368 <<>>=\r
369 align(tli.table) <- "|rrl|l|lr|"\r
370 @\r
371 <<results='asis'>>=\r
372 tli.table\r
373 @\r
374 \vspace{12pt}\textbf{\itshape Fixed width columns}\r
375 <<>>=\r
376 align(tli.table) <- "|rr|lp{3cm}l|r|"\r
377 @\r
378 <<results='asis'>>=\r
379 tli.table\r
380 @\r
381 \r
382 \subsection{Significant digits}\r
383 Specify with a single argument\r
384 <<>>=\r
385 digits(tli.table) <- 3\r
386 @\r
387 <<results='asis'>>=\r
388 tli.table\r
389 @\r
390 \r
391 \vspace{12pt}\r
392 or one for each column, counting the row names,\r
393 <<>>=\r
394 digits(tli.table) <- 1:(ncol(tli)+1)\r
395 @\r
396 <<results='asis'>>=\r
397 tli.table\r
398 @\r
399 \r
400 \vspace{12pt}\r
401 or as a full matrix\r
402 <<>>=\r
403 digits(tli.table) <- matrix( 0:4, nrow = 10, ncol = ncol(tli)+1 )\r
404 @\r
405 <<results='asis'>>=\r
406 tli.table\r
407 @\r
408 \r
409 \subsection{Suppress row names}\r
410 <<results='asis'>>=\r
411 print(tli.table, include.rownames = FALSE)\r
412 @\r
413 \r
414 \vspace{12pt} If you want a vertical line on the left, you need to\r
415 change the \code{align} attribute.\r
416 <<>>=\r
417 align(tli.table) <- "|r|r|lp{3cm}l|r|"\r
418 @\r
419 <<results='asis'>>=\r
420 print(tli.table, include.rownames = FALSE)\r
421 @\r
422 \r
423 \vspace{12pt} Revert the alignment to what is was before.\r
424 <<>>=\r
425 align(tli.table) <- "|rr|lp{3cm}l|r|"\r
426 @\r
427 \r
428 \subsection{Suppress column names}\r
429 <<results='asis'>>=\r
430 print(tli.table, include.colnames = FALSE)\r
431 @\r
432 \r
433 \vspace{12pt}\r
434 Note the doubled header lines which can be suppressed with, eg,\r
435 <<results='asis'>>=\r
436 print(tli.table, include.colnames = FALSE,\r
437       hline.after = c(0,nrow(tli.table)))\r
438 @\r
439 \r
440 \subsection{Suppress row and column names}\r
441 <<results='asis'>>=\r
442 print(tli.table, include.colnames = FALSE, include.rownames = FALSE)\r
443 @\r
444 \r
445 \subsection{Rotate row and column names}\r
446 The \texttt{rotate.rownames } and \texttt{rotate.colnames} arguments can be\r
447 used to rotate the row and/or column names.\r
448 \r
449 <<results='asis'>>=\r
450 print(tli.table, rotate.rownames = TRUE, rotate.colnames = TRUE)\r
451 @\r
452 \r
453 \subsection{Horizontal lines}\r
454 \vspace{12pt}\textbf{\itshape Line locations}\r
455 \r
456 Use the \texttt{hline.after} argument to specify the position of the\r
457 horizontal lines.\r
458 \r
459 <<results='asis'>>=\r
460 print(xtable(anova(glm.D93)), hline.after = c(1))\r
461 @\r
462 \r
463 \vspace{12pt}\textbf{\itshape Line styles}\r
464 \r
465 The \LaTeX package \pkg{ booktabs} can be used to specify different\r
466 line style tags for top, middle, and bottom lines.  Specifying\r
467 \code{ booktabs = TRUE} will lead to separate tags being generated\r
468 for the three line types.\r
469 \r
470 Insert \verb|\usepackage{booktabs}| in your \LaTeX preamble and define\r
471 the \texttt{toprule}, \texttt{midrule}, and \texttt{bottomrule}\r
472 tags to specify the line styles. By default, when no value is given\r
473 for \texttt{hline.after}, a \texttt{toprule} will be drawn above the\r
474 table, a \texttt{midrule} after the table headings and a\r
475 \texttt{bottomrule} below the table. The width of the top and bottom\r
476 rules can be set by supplying a value to \verb+\heavyrulewidth+. The\r
477 width of the midrules can be set by supplying a value to\r
478 \verb+\lightrulewidth+. The following tables have\r
479 \verb+\heavyrulewidth = 2pt+ and \verb+\lightrulewidth = 0.5pt+, to\r
480 ensure the difference in weight is noticeable.\r
481 \r
482 There is no support for \verb+\cmidrule+ or \verb+\specialrule+\r
483 although they are part of the \texttt{booktabs} package.\r
484 \r
485 \heavyrulewidth = 2pt\r
486 \lightrulewidth = 0.5pt\r
487 \r
488 <<results='asis'>>=\r
489 print(tli.table, booktabs = TRUE)\r
490 @\r
491 \r
492 \vspace{12pt}\r
493 If \texttt{hline.after} includes $-1$, a \texttt{toprule} will be\r
494 drawn above the table. If \texttt{hline.after} includes the number of\r
495 rows in the table, a \texttt{bottomrule} will be drawn below the\r
496 table. For any other values specified in \texttt{hline.after}, a\r
497 \texttt{midrule} will be drawn after that line of the table.\r
498 \r
499 The next table has more than one \texttt{midrule}.\r
500 \r
501 <<>>=\r
502 bktbs <- xtable(matrix(1:10, ncol = 2))\r
503 hlines <- c(-1,0,1,nrow(bktbs))\r
504 @\r
505 This command produces the required table.\r
506 <<results='asis'>>=\r
507 print(bktbs, booktabs = TRUE, hline.after = hlines)\r
508 @\r
509 \r
510 \subsection{Table-level LaTeX}\r
511 <<results='asis'>>=\r
512 print(xtable(anova(glm.D93)), size = "small")\r
513 @\r
514 \r
515 \subsection{Long tables}\r
516 Remember to insert \verb|\usepackage{longtable}| in your \LaTeX preamble.\r
517 \r
518 <<longtable>>=\r
519 ## Demonstration of longtable support.\r
520 x <- matrix(rnorm(1000), ncol = 10)\r
521 x.big <- xtable(x, label = 'tabbig',\r
522                 caption = 'Example of \\code{longtable} spanning several pages')\r
523 @\r
524 <<results='asis'>>=\r
525 print(x.big, tabular.environment = 'longtable')\r
526 @\r
527 \r
528 %%\r
529 %% The column name alignment is off in the following example.\r
530 %% It needs some revision before exposing it. - CR, 7/2/2012\r
531 %%\r
532 %\r
533 %\vspace{12pt}\textbf{\itshape Long tables with the header on each page}\r
534 %\r
535 %The \texttt{add.to.row} argument can be used to display the header\r
536 %for a long table on each page, and to add a "continued" footer\r
537 %on all pages except the last page.\r
538 %\r
539 %<<results=tex>>=\r
540 %library(xtable)\r
541 %x<-matrix(rnorm(1000), ncol = 10)\r
542 %addtorow<-list()\r
543 %addtorow$pos<-list()\r
544 %addtorow$pos[[1]]<-c(0)\r
545 %addtorow$command<-c(paste(\r
546 %    "\\hline \n",\r
547 %    "  \\endhead \n",\r
548 %    "  \\hline \n",\r
549 %    "  {\\footnotesize Continued on next page} \n",\r
550 %    "  \\endfoot \n",\r
551 %    "  \\endlastfoot \n", sep = ""))\r
552 %x.big2 <- xtable(x, label = "tabbig2",\r
553 %    caption = "Example of longtable with the header on each page")\r
554 %print(x.big2, tabular.environment = "longtable",\r
555 %include.rownames = FALSE, add.to.row = addtorow, hline.after = c(-1) )\r
556 %@\r
557 \r
558 \subsection{Sideways tables}\r
559 Remember to insert \verb|\usepackage{rotating}| in your LaTeX\r
560 preamble.  Sideways tables can't be forced in place with the `H'\r
561 specifier, but you can use the \verb|\clearpage| command to get them\r
562 fairly nearby.\r
563 \r
564 <<>>=\r
565 x <- x[1:30, ]\r
566 x.small <- xtable(x, label = 'tabsmall', caption = 'A sideways table')\r
567 @\r
568 \r
569 <<results='asis'>>=\r
570 print(x.small, floating = TRUE, floating.environment = 'sidewaystable')\r
571 @\r
572 \clearpage\r
573 \r
574 \subsection{Rescaled tables}\r
575 Specify a \texttt{scalebox} value to rescale the table.\r
576 \r
577 <<>>=\r
578 x <- x[1:20, ]\r
579 x.rescale <- xtable(x, label = 'tabrescaled', caption = 'A rescaled table')\r
580 @\r
581 \r
582 <<results='asis'>>=\r
583 print(x.rescale, scalebox = 0.7)\r
584 @\r
585 \r
586 \subsection{Table Width}\r
587 The \texttt{tabularx} tabular environment provides more alignment options,\r
588 and has a \texttt{width} argument to specify the table width.\r
589 \r
590 Remember to insert \verb|\usepackage{tabularx}| in your \LaTeX\ preamble.\r
591 \r
592 <<>>=\r
593 df.width <- data.frame(\r
594     "label 1 with much more text than is needed" = c("item 1", "A"),\r
595     "label 2 is also very long" = c("item 2","B"),\r
596     "label 3" = c("item 3","C"),\r
597     "label 4" = c("item 4 but again with too much text","D"),\r
598     check.names = FALSE)\r
599 \r
600 x.width <- xtable(df.width,\r
601                   caption = "Using the 'tabularx' environment")\r
602 align(x.width) <- "|l|X|X|l|X|"\r
603 @\r
604 \r
605 <<results='asis'>>=\r
606 print(x.width, tabular.environment = "tabularx",\r
607       width = "\\textwidth")\r
608 @\r
609 \r
610 \section{Suppressing Printing}\r
611 By default the \texttt{print} method will print the LaTeX or HTML to standard\r
612 output and also return the character strings invisibly.  The printing to\r
613 standard output can be suppressed by specifying \texttt{print.results = FALSE}.\r
614 \r
615 <<>>=\r
616 x.out <- print(tli.table, print.results = FALSE)\r
617 @\r
618 \r
619 Formatted output can also be captured without printing with the\r
620 \texttt{toLatex} method.  This function returns an object of class\r
621 \texttt{"Latex"}.\r
622 \r
623 <<>>=\r
624 x.ltx <- toLatex(tli.table)\r
625 class(x.ltx)\r
626 x.ltx\r
627 @\r
628 \r
629 \section{Acknowledgements}\r
630 Most of the examples in this gallery are taken from the \texttt{xtable}\r
631 documentation.\r
632 \r
633 \section{R Session information}\r
634 <<results='asis'>>=\r
635 toLatex(sessionInfo())\r
636 @\r
637 \r
638 \end{document}\r