]> git.donarmstrong.com Git - xtable.git/blob - pkg/vignettes/xtableGallery.Rnw
Added math.style.exponents option to print.xtable via a change to
[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}\r
9 \usepackage[a4paper,height=24cm]{geometry} % geometry first\r
10 \usepackage{array}\r
11 \usepackage{booktabs}\r
12 \usepackage{longtable}\r
13 \usepackage{parskip}\r
14 \usepackage{rotating}\r
15 \usepackage{tabularx}\r
16 \usepackage{titlesec}\r
17 \usepackage{hyperref} % hyperref last\r
18 \titleformat\subsubsection{\bfseries\itshape}{}{0pt}{}\r
19 \newcommand\p{\vspace{2ex}}\r
20 \newcommand\code[1]{\texttt{#1}}\r
21 \newcommand\pkg[1]{\textbf{#1}}\r
22 \setcounter{tocdepth}{2}\r
23 \begin{document}\r
24 \r
25 \title{The \pkg{xtable} Gallery}\r
26 \author{Jonathan Swinton and others}\r
27 \maketitle\r
28 \r
29 \tableofcontents\r
30 \r
31 \newpage\r
32 \r
33 \section{Introduction}\r
34 This document gives a gallery of tables which can be made using the\r
35 \pkg{xtable} package to create \LaTeX\ output. It doubles as a\r
36 regression check for the package.\r
37 \r
38 <<include=FALSE>>=\r
39 library(knitr)\r
40 opts_chunk$set(fig.path='figdir/fig', debug=TRUE, echo=TRUE)\r
41 @\r
42 \r
43 The first step is to load the package and set an option for this document.\r
44 <<results='asis'>>=\r
45 library(xtable)\r
46 options(xtable.floating = FALSE)\r
47 options(xtable.timestamp = "")\r
48 @\r
49 \r
50 \section{Gallery}\r
51 \subsection{Data frame}\r
52 <<results='asis'>>=\r
53 data(tli)\r
54 xtable(tli[1:10, ])\r
55 @\r
56 \r
57 \subsection{Matrix}\r
58 <<results='asis'>>=\r
59 design.matrix <- model.matrix(~ sex*grade, data = tli[1:10, ])\r
60 xtable(design.matrix, digits = 0)\r
61 @\r
62 \r
63 \newpage\r
64 \subsection{aov}\r
65 <<results='asis'>>=\r
66 fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data = tli)\r
67 xtable(fm1)\r
68 @\r
69 \r
70 \subsection{lm}\r
71 <<results='asis'>>=\r
72 fm2 <- lm(tlimth ~ sex*ethnicty, data = tli)\r
73 xtable(fm2)\r
74 @\r
75 \r
76 \subsubsection{Anova table (one model)}\r
77 <<results='asis'>>=\r
78 xtable(anova(fm2))\r
79 @\r
80 \r
81 \subsubsection{Anova table (two models)}\r
82 <<results='asis'>>=\r
83 fm2b <- lm(tlimth ~ ethnicty, data = tli)\r
84 xtable(anova(fm2b, fm2))\r
85 @\r
86 \r
87 \newpage\r
88 \subsection{glm}\r
89 <<results='asis'>>=\r
90 fm3 <- glm(disadvg ~ ethnicty*grade, data = tli, family = binomial)\r
91 xtable(fm3)\r
92 @\r
93 \r
94 \subsubsection{Analysis of deviance}\r
95 <<results='asis'>>=\r
96 xtable(anova(fm3))\r
97 @\r
98 \r
99 \subsection{prcomp}\r
100 <<results='asis'>>=\r
101 pr1 <- prcomp(USArrests)\r
102 xtable(pr1)\r
103 @\r
104 \r
105 \p\r
106 <<results='asis'>>=\r
107 xtable(summary(pr1))\r
108 @\r
109 \r
110 <<include=FALSE>>=\r
111 # pr2 <- princomp(USArrests)\r
112 # xtable(pr2)\r
113 @\r
114 \r
115 \newpage\r
116 \r
117 \subsection{Time series}\r
118 <<results='asis'>>=\r
119 temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)),\r
120               start = c(1954, 7), frequency = 12)\r
121 temp.table <- xtable(temp.ts, digits = 0)\r
122 temp.table\r
123 @\r
124 \r
125 \newpage\r
126 \r
127 <<include=FALSE>>=\r
128 # ## Demonstrate saving to file\r
129 # for(i in c("latex", "html")) {\r
130 #   outFileName <- paste("xtable.", ifelse(i=="latex", "tex", i), sep = "")\r
131 #   print(xtable(lm.D9), type = i, file = outFileName, append = TRUE,\r
132 #         latex.environments = NULL)\r
133 #   print(xtable(lm.D9), type = i, file = outFileName, append = TRUE,\r
134 #         latex.environments = "")\r
135 #   print(xtable(lm.D9), type = i, file = outFileName, append = TRUE,\r
136 #         latex.environments = "center")\r
137 #   print(xtable(anova(glm.D93, test = "Chisq")),\r
138 #         type = i, file = outFileName,\r
139 #         append = TRUE)\r
140 #   print(xtable(anova(glm.D93)), hline.after = c(1),\r
141 #         size = "small", type = i,\r
142 #         file = outFileName, append = TRUE)\r
143 #   # print(xtable(pr2), type = i, file = outFileName, append = TRUE)\r
144 # }\r
145 @\r
146 \r
147 \section{Automatic formatting}\r
148 \subsection{Suggest alignment, digits, and display}\r
149 The functions \code{xalign}, \code{xdigits}, and \code{xdisplay} are useful for\r
150 formatting tables in a sensible way. Consider the output produced by the default\r
151 formatting.\r
152 \r
153 <<results='asis'>>=\r
154 dat <- mtcars[1:3, 1:6]\r
155 x <- xtable(dat)\r
156 x\r
157 @\r
158 \r
159 \p\r
160 Now change the default alignment, digits and display using helper functions\r
161 \code{xalign}, \code{xdigits}, and \code{xdisplay}. This produces a better\r
162 format as shown below.\r
163 \r
164 <<results='asis'>>=\r
165 align(x) <- xalign(x)\r
166 digits(x) <- xdigits(x)\r
167 display(x) <- xdisplay(x)\r
168 x\r
169 @\r
170 \r
171 \subsection{Shorthand notation}\r
172 For convenience, the three `autoformat' functions (\code{xalign},\r
173 \code{xdigits}, and \code{xdisplay}) can be applied together when an\r
174 \code{xtable} is created, using the \code{auto} argument:\r
175 \r
176 <<results='asis'>>=\r
177 xtable(dat, auto = TRUE)\r
178 @\r
179 \r
180 \p\r
181 Similarly, the \code{autoformat} function can be used to postprocess an\r
182 existing \code{xtable}:\r
183 \r
184 <<results='asis'>>=\r
185 x <- xtable(dat)\r
186 autoformat(x)\r
187 @\r
188 \r
189 \newpage\r
190 \r
191 \subsection{Math-Style Exponents}\r
192 If you prefer $5 \times 10^5$ in your tables to 5e5, the\r
193 \code{math.style.exponents} option to \code{print.xtable} is useful:\r
194 \r
195 <<results='asis'>>=\r
196 print(xtable(data.frame(text=c("foo","bar"),\r
197                         googols=c(10e10,50e10),\r
198                         small=c(8e-24,7e-5),\r
199                         row.names=c("A","B")),\r
200              display=c("s","s","g","g")),\r
201       math.style.exponents=TRUE\r
202       )\r
203\r
204 \r
205 this option also supports the values \code{ensuremath} which uses\r
206 \code{\char`\\ensuremath} instead of \code{\$\$} and \code{UTF-8}\r
207 which uses UTF-8 to approximate the \LaTeX typesetting.\r
208 \r
209 \r
210 \section{Sanitization}\r
211 <<results='asis'>>=\r
212 insane <- data.frame(Name = c("Ampersand","Greater than","Less than",\r
213                             "Underscore","Per cent","Dollar",\r
214                             "Backslash","Hash","Caret","Tilde",\r
215                             "Left brace","Right brace"),\r
216                      Character = I(c("&",">","<","_","%","$",\r
217                                      "\\","#","^","~","{","}")))\r
218 colnames(insane)[2] <- paste(insane[, 2], collapse = "")\r
219 xtable(insane)\r
220 @\r
221 \r
222 \p\r
223 Sometimes you might want to have your own sanitization function.\r
224 \r
225 \r
226 <<results='asis'>>=\r
227 wanttex <- xtable(data.frame(Column =\r
228                              paste("Value_is $10^{-",1:3,"}$", sep = "")))\r
229 print(wanttex, sanitize.text.function =\r
230       function(str) gsub("_", "\\_", str, fixed = TRUE))\r
231 @\r
232 \r
233 \p\r
234 Sanitization can be useful in formatting column headings and row names:\r
235 \r
236 <<sanitize3>>=\r
237 dat <- mtcars[1:3, 1:6]\r
238 large <- function(x){\r
239   paste0('{\\Large{\\bfseries ', x, '}}')\r
240 }\r
241 italic <- function(x){\r
242   paste0('{\\emph{ ', x, '}}')\r
243 }\r
244 @ %def\r
245 \r
246 <<sanitize4, results = 'asis'>>=\r
247 print(xtable(dat),\r
248       sanitize.rownames.function = italic,\r
249       sanitize.colnames.function = large,\r
250       booktabs = TRUE)\r
251 @ %def\r
252 \r
253 \r
254 \r
255 \newpage\r
256 \r
257 \subsection{Markup in tables}\r
258 Markup can be included in tables, including in column and row names, by using\r
259 a custom \code{sanitize.text.function}.\r
260 \r
261 <<results='asis'>>=\r
262 mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)\r
263 rownames(mat) <- "$y_{t-1}$"\r
264 colnames(mat) <- c("$R^2$", "$\\bar{x}$", "F-stat", "S.E.E", "DW")\r
265 mat <- xtable(mat)\r
266 print(mat, sanitize.text.function = function(x) {x})\r
267 @\r
268 \r
269 % By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.\r
270 \p\r
271 You can also have sanitize functions that are specific to column or\r
272 row names.  In the table below, the row name is not sanitized but\r
273 column names and table elements are.\r
274 \r
275 <<results='asis'>>=\r
276 money <- matrix(c("$1,000","$900","$100"), ncol = 3,\r
277                 dimnames = list("$\\alpha$",\r
278                                 c("Income (US$)","Expenses (US$)",\r
279                                   "Profit (US$)")))\r
280 print(xtable(money), sanitize.rownames.function = function(x) {x})\r
281 @\r
282 \r
283 \section{Format examples}\r
284 \subsection{Adding a centering environment}\r
285 <<results='asis'>>=\r
286 print(xtable(anova(fm3), caption = "\\tt latex.environments = \"\""),\r
287       floating = TRUE, latex.environments = "")\r
288 print(xtable(anova(fm3), caption = "\\tt latex.environments = \"center\""),\r
289       floating = TRUE, latex.environments = "center")\r
290 @\r
291 \r
292 \newpage\r
293 \r
294 \subsection{Column alignment}\r
295 <<results='asis'>>=\r
296 tli.table <- xtable(tli[1:10, ])\r
297 align(tli.table) <- rep("r", 6)\r
298 tli.table\r
299 @\r
300 \r
301 \subsubsection{Left aligned strings with column lines}\r
302 <<results='asis'>>=\r
303 align(tli.table) <- "|rrl|l|lr|"\r
304 tli.table\r
305 @\r
306 \r
307 \subsubsection{Fixed width columns}\r
308 <<results='asis'>>=\r
309 align(tli.table) <- "|rr|lp{3cm}l|r|"\r
310 tli.table\r
311 @\r
312 \r
313 \newpage\r
314 \r
315 \subsection{Number of digits}\r
316 One number for all columns,\r
317 <<results='asis'>>=\r
318 display(tli.table)[c(2,6)] <- "f"\r
319 digits(tli.table) <- 3\r
320 tli.table\r
321 @\r
322 \r
323 \p\r
324 or one for each column, including the row names,\r
325 <<results='asis'>>=\r
326 digits(tli.table) <- 1:(ncol(tli)+1)\r
327 tli.table\r
328 @\r
329 \r
330 \p\r
331 or as a full matrix.\r
332 <<results='asis'>>=\r
333 digits(tli.table) <- matrix(0:4, nrow = 10, ncol = ncol(tli)+1)\r
334 tli.table\r
335 @\r
336 \r
337 \newpage\r
338 \r
339 \subsection{Suppress row/column names}\r
340 \subsubsection{Suppress row names}\r
341 <<results='asis'>>=\r
342 tli.table <- xtable(tli[1:10, ])\r
343 print(tli.table, include.rownames = FALSE)\r
344 @\r
345 \r
346 \p\r
347 If you want a vertical line on the left, you need to change the \code{align}\r
348 attribute.\r
349 <<results='asis'>>=\r
350 align(tli.table) <- "|r|r|lp{3cm}l|r|"\r
351 print(tli.table, include.rownames = FALSE)\r
352 @\r
353 \r
354 \p\r
355 Revert the alignment to what is was before.\r
356 <<>>=\r
357 align(tli.table) <- "|rr|lp{3cm}l|r|"\r
358 @\r
359 \r
360 \newpage\r
361 \r
362 \subsubsection{Suppress column names}\r
363 <<results='asis'>>=\r
364 print(tli.table, include.colnames = FALSE)\r
365 @\r
366 \r
367 \p\r
368 Note the doubled header lines which can be suppressed.\r
369 <<results='asis'>>=\r
370 print(tli.table, include.colnames = FALSE,\r
371       hline.after = c(0,nrow(tli.table)))\r
372 @\r
373 \r
374 \subsubsection{Suppress row and column names}\r
375 <<results='asis'>>=\r
376 print(tli.table, include.colnames = FALSE, include.rownames = FALSE)\r
377 @\r
378 \r
379 \newpage\r
380 \r
381 \subsection{Rotate row/column names}\r
382 The \code{rotate.rownames} and \code{rotate.colnames} arguments can be used to\r
383 rotate the row and/or column names. This requires \verb|\usepackage{rotating}|\r
384 in the \LaTeX\ preamble.\r
385 \r
386 <<results='asis'>>=\r
387 print(tli.table, rotate.rownames = TRUE, rotate.colnames = TRUE)\r
388 @\r
389 \r
390 \newpage\r
391 \r
392 \subsection{Horizontal lines}\r
393 \subsubsection{Line locations}\r
394 Use the \code{hline.after} argument to specify the position of the\r
395 horizontal lines.\r
396 \r
397 <<results='asis'>>=\r
398 print(xtable(anova(fm3)), hline.after = c(1))\r
399 @\r
400 \r
401 \subsubsection{Line styles}\r
402 Specifying \code{booktabs = TRUE} will generate three line types. By default,\r
403 when no value is given for \code{hline.after}, a \verb|\toprule| will be drawn\r
404 above the table, a \verb|\midrule| after the table headings and a\r
405 \verb|\bottomrule| below the table. This requires \verb|\usepackage{booktabs}|\r
406 in the \LaTeX\ preamble.\r
407 \r
408 \p\r
409 The top and bottom rules are slightly thicker than the mid rule. The thickness\r
410 of the lines can be set via the \LaTeX\ lengths \verb|\heavyrulewidth| and\r
411 \verb|\lightrulewidth|.\r
412 \r
413 <<results='asis'>>=\r
414 tli.table <- xtable(tli[1:10, ])\r
415 print(tli.table, include.rownames = FALSE, booktabs = TRUE)\r
416 @\r
417 \r
418 \p\r
419 If \code{hline.after} includes \code{-1}, a \verb|\toprule| will be\r
420 drawn above the table. If \code{hline.after} includes the number of\r
421 rows in the table, a \verb|\bottomrule| will be drawn below the\r
422 table. For any other values specified in \code{hline.after}, a\r
423 \verb|\midrule| will be drawn after that line of the table.\r
424 \r
425 \p\r
426 The following table has more than one \verb|\midrule|.\r
427 \r
428 <<results='asis'>>=\r
429 bktbs <- xtable(matrix(1:10, ncol = 2))\r
430 hlines <- c(-1, 0, 1, nrow(bktbs))\r
431 print(bktbs, booktabs = TRUE, hline.after = hlines)\r
432 @\r
433 \r
434 \subsection{Table level commands}\r
435 <<results='asis'>>=\r
436 print(xtable(anova(fm3)), size = "large")\r
437 @\r
438 \r
439 \p\r
440 <<results='asis'>>=\r
441 print(xtable(anova(fm3)), size = "\\setlength{\\tabcolsep}{12pt}")\r
442 @\r
443 \r
444 \subsection{Long tables}\r
445 Requires \verb|\usepackage{longtable}| in the \LaTeX\ preamble.\r
446 \r
447 <<results='asis'>>=\r
448 x <- matrix(rnorm(1000), ncol = 10)\r
449 x.big <- xtable(x, caption = "A \\code{longtable} spanning several pages")\r
450 print(x.big, hline.after=c(-1, 0), tabular.environment = "longtable")\r
451 @\r
452 \r
453 %% The column name alignment is off in the following example.\r
454 %% It needs some revision before exposing it. - CR, 7/2/2012\r
455 %\r
456 %% Tried to fix this and got some of the way, but \hlines are wrong\r
457 %% and first column is too wide. - DJS 4/10/2014\r
458 %% \subsubsection{Long tables with the header on each page}\r
459 %% The \code{add.to.row} argument can be used to display the header\r
460 %% for a long table on each page, and to add a "continued" footer\r
461 %% on all pages except the last page.\r
462 \r
463 %% \newcommand{\head}[1]{\centercell{\bfseries#1}}\r
464 \r
465 %% <<results='asis'>>=\r
466 %% x <- matrix(rnorm(1000), ncol = 10)\r
467 %% hdr <-  paste(paste("\\multicolumn{1}{c}{",1:9,"} & ", collapse = ""),\r
468 %%               "\\multicolumn{1}{c}{10}\\\\")\r
469 %% addtorow <- list()\r
470 %% addtorow$pos <- list()\r
471 %% addtorow$pos[[1]] <- c(0)\r
472 %% addtorow$command <- c(paste(\r
473 %%     hdr,\r
474 %%     "  \\hline \n",\r
475 %%     "  \\endhead \n",\r
476 %%     "  \\hline \n",\r
477 %%     "  {\\footnotesize Continued on next page} \n",\r
478 %%     "  \\endfoot \n",\r
479 %%     "  \\endlastfoot \n", sep = ""))\r
480 %% x.big2 <- xtable(x, label = "tabbig2", align = "lrrrrrrrrrr",\r
481 %%                  caption = "Example of longtable with the header on each page")\r
482 %% print(x.big2, tabular.environment = "longtable",\r
483 %%       include.rownames = FALSE, include.colnames = FALSE,\r
484 %%       add.to.row = addtorow)\r
485 %% @\r
486 \r
487 \newpage\r
488 \r
489 \subsection{Use of \code{add.to.row} argument}\r
490 The following frequency table has outer dimnames: \code{Grade3} and\r
491 \code{Grade6}.\r
492 \r
493 <<>>=\r
494 Grade3 <- c("A","B","B","A","B","C","C","D","A","B",\r
495             "C","C","C","D","B","B","D","C","C","D")\r
496 Grade6 <- c("A","A","A","B","B","B","B","B","C","C",\r
497             "A","C","C","C","D","D","D","D","D","D")\r
498 Cohort <- table(Grade3, Grade6)\r
499 Cohort\r
500 @\r
501 \r
502 \p\r
503 The default behavior of \code{print.xtable} is to strip outer dimnames.\r
504 <<results='asis'>>=\r
505 xtable(Cohort)\r
506 @\r
507 \r
508 \p\r
509 The desired column labels can be created using \code{add.to.row}, in this case\r
510 applying two commands to ``row number zero'' while suppressing the basic column\r
511 names.\r
512 \r
513 <<results='asis'>>=\r
514 addtorow <- list()\r
515 addtorow$pos <- list(0, 0)\r
516 addtorow$command <- c("& \\multicolumn{4}{c}{Grade 6} \\\\\n",\r
517                       "Grade 3 & A & B & C & D \\\\\n")\r
518 print(xtable(Cohort), add.to.row = addtorow, include.colnames = FALSE)\r
519 @\r
520 \r
521 \subsection{Sideways tables}\r
522 Requires \verb|\usepackage{rotating}| in the LaTeX\r
523 preamble.  Sideways tables can't be forced in place with the \code{[H]}\r
524 specifier, but you can use the \verb|\clearpage| command to get them\r
525 fairly nearby.\r
526 \r
527 <<results='asis'>>=\r
528 x <- x[1:30, ]\r
529 x.side <- xtable(x, caption = "A sideways table")\r
530 print(x.side, floating = TRUE, floating.environment = "sidewaystable")\r
531 @\r
532 \clearpage\r
533 \r
534 \subsection{Rescaled tables}\r
535 Specify a \code{scalebox} value to rescale the table.\r
536 <<results='asis'>>=\r
537 x <- x[1:20, ]\r
538 x.rescale <- xtable(x)\r
539 print(x.rescale, scalebox = 0.7)\r
540 @\r
541 \r
542 \subsection{Aligning fixed width columns}\r
543 Note that using specifications such as \verb|p{2cm}| always\r
544 produces a \textbf{left aligned} column. What if some other alignment\r
545 is desired?\r
546 \r
547 This is not really a problem with \pkg{xtable} but with the formatting\r
548 of tables with fixed width columns and different alignments using\r
549 standard \LaTeX.\r
550 \r
551 One solution is to use the \verb|array| package, defining new\r
552 column formats.\r
553 \r
554 \begin{verbatim}\r
555 \newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
556     \arraybackslash\hspace{0pt}}m{#1}}\r
557 \newcolumntype{C}[1]{>{\centering\let\newline\\\r
558     \arraybackslash\hspace{0pt}}m{#1}}\r
559 \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\r
560     \arraybackslash\hspace{0pt}}m{#1}}\r
561 \newcolumntype{P}[1]{>{\raggedright\tabularxbackslash}p{#1}}\r
562 \end{verbatim}\r
563 \r
564 These allow for very sophisticated cell formatting, namely\r
565 left-aligned, centred, or right-aligned text, with recognition of line\r
566 breaks for the first three new column types. If these lines are\r
567 included along with \verb|\usepackage{array}|, then the following\r
568 is possible.\r
569 \r
570 \newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
571     \arraybackslash\hspace{0pt}}m{#1}}\r
572 \newcolumntype{C}[1]{>{\centering\let\newline\\\r
573     \arraybackslash\hspace{0pt}}m{#1}}\r
574 \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\r
575     \arraybackslash\hspace{0pt}}m{#1}}\r
576 \newcolumntype{P}[1]{>{\raggedright\tabularxbackslash}p{#1}}\r
577 \r
578 <<results='asis'>>=\r
579 df <- data.frame(name = c("A","B"), right = c(1.4, 34.6),\r
580                  left = c(1.4, 34.6), text = c("txt1","txt2"))\r
581 print(xtable(df, align = c("l", "|c", "|R{3cm}", "|L{3cm}", "| p{3cm}|")),\r
582       floating = FALSE, include.rownames = FALSE)\r
583 @\r
584 \r
585 \newpage\r
586 \r
587 \subsection{Table width}\r
588 The \code{tabularx} environment is for typesetting tables whose overall width is\r
589 fixed. The column alignment code \code{X} denotes columns that will be stretched\r
590 to achieve the desired table width. Requires \verb|\usepackage{tabularx}| in the\r
591 \LaTeX\ preamble.\r
592 \r
593 <<results='asis'>>=\r
594 df.width <- data.frame(One = c("item 1", "A"), Two = c("item 2", "B"),\r
595                        Three = c("item 3", "C"), Four = c("item 4", "D"))\r
596 x.width <- xtable(df.width)\r
597 align(x.width) <- "|l|X|l|l|l|"\r
598 print(x.width, tabular.environment = "tabularx", width = "\\textwidth")\r
599 @\r
600 \r
601 \section{Suppressing printing}\r
602 By default the \code{print} method will print the \LaTeX\ or HTML to standard\r
603 output and also return the character strings invisibly.  The printing to\r
604 standard output can be suppressed by specifying \code{print.results = FALSE}.\r
605 \r
606 <<>>=\r
607 x.out <- print(tli.table, print.results = FALSE)\r
608 @\r
609 \r
610 Formatted output can also be captured without printing with the\r
611 \code{toLatex} method.  This function returns an object of class\r
612 \code{"Latex"}.\r
613 \r
614 <<>>=\r
615 x.ltx <- toLatex(tli.table)\r
616 class(x.ltx)\r
617 x.ltx\r
618 @\r
619 \r
620 \newpage\r
621 \r
622 \section{Acknowledgements}\r
623 Most of the examples in this gallery are taken from the \pkg{xtable}\r
624 documentation. Two examples (\code{add.to.row} and `Aligning fixed width\r
625 columns') are from Stack Exchange.\r
626 \r
627 \section{Session information}\r
628 <<results='asis'>>=\r
629 toLatex(sessionInfo())\r
630 @\r
631 \r
632 \end{document}\r