]> git.donarmstrong.com Git - xtable.git/blob - pkg/vignettes/xtableGallery.Rnw
6b7d47b3327244659e9d49a14a5c1a181019a941
[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 \section{Sanitization}\r
192 <<results='asis'>>=\r
193 insane <- data.frame(Name = c("Ampersand","Greater than","Less than",\r
194                             "Underscore","Per cent","Dollar",\r
195                             "Backslash","Hash","Caret","Tilde",\r
196                             "Left brace","Right brace"),\r
197                      Character = I(c("&",">","<","_","%","$",\r
198                                      "\\","#","^","~","{","}")))\r
199 colnames(insane)[2] <- paste(insane[, 2], collapse = "")\r
200 xtable(insane)\r
201 @\r
202 \r
203 \p\r
204 Sometimes you might want to have your own sanitization function.\r
205 \r
206 \r
207 <<results='asis'>>=\r
208 wanttex <- xtable(data.frame(Column =\r
209                              paste("Value_is $10^{-",1:3,"}$", sep = "")))\r
210 print(wanttex, sanitize.text.function =\r
211       function(str) gsub("_", "\\_", str, fixed = TRUE))\r
212 @\r
213 \r
214 \p\r
215 Sanitization can be useful in formatting column headings and row names:\r
216 \r
217 <<sanitize3>>=\r
218 dat <- mtcars[1:3, 1:6]\r
219 large <- function(x){\r
220   paste0('{\\Large{\\bfseries ', x, '}}')\r
221 }\r
222 italic <- function(x){\r
223   paste0('{\\emph{ ', x, '}}')\r
224 }\r
225 @ %def\r
226 \r
227 <<sanitize4, results = 'asis'>>=\r
228 print(xtable(dat),\r
229       sanitize.rownames.function = italic,\r
230       sanitize.colnames.function = large,\r
231       booktabs = TRUE)\r
232 @ %def\r
233 \r
234 \r
235 \r
236 \newpage\r
237 \r
238 \subsection{Markup in tables}\r
239 Markup can be included in tables, including in column and row names, by using\r
240 a custom \code{sanitize.text.function}.\r
241 \r
242 <<results='asis'>>=\r
243 mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)\r
244 rownames(mat) <- "$y_{t-1}$"\r
245 colnames(mat) <- c("$R^2$", "$\\bar{x}$", "F-stat", "S.E.E", "DW")\r
246 mat <- xtable(mat)\r
247 print(mat, sanitize.text.function = function(x) {x})\r
248 @\r
249 \r
250 % By David Dahl to demonstrate contribution from David Whitting, 2007-10-09.\r
251 \p\r
252 You can also have sanitize functions that are specific to column or\r
253 row names.  In the table below, the row name is not sanitized but\r
254 column names and table elements are.\r
255 \r
256 <<results='asis'>>=\r
257 money <- matrix(c("$1,000","$900","$100"), ncol = 3,\r
258                 dimnames = list("$\\alpha$",\r
259                                 c("Income (US$)","Expenses (US$)",\r
260                                   "Profit (US$)")))\r
261 print(xtable(money), sanitize.rownames.function = function(x) {x})\r
262 @\r
263 \r
264 \section{Format examples}\r
265 \subsection{Adding a centering environment}\r
266 <<results='asis'>>=\r
267 print(xtable(anova(fm3), caption = "\\tt latex.environments = \"\""),\r
268       floating = TRUE, latex.environments = "")\r
269 print(xtable(anova(fm3), caption = "\\tt latex.environments = \"center\""),\r
270       floating = TRUE, latex.environments = "center")\r
271 @\r
272 \r
273 \newpage\r
274 \r
275 \subsection{Column alignment}\r
276 <<results='asis'>>=\r
277 tli.table <- xtable(tli[1:10, ])\r
278 align(tli.table) <- rep("r", 6)\r
279 tli.table\r
280 @\r
281 \r
282 \subsubsection{Left aligned strings with column lines}\r
283 <<results='asis'>>=\r
284 align(tli.table) <- "|rrl|l|lr|"\r
285 tli.table\r
286 @\r
287 \r
288 \subsubsection{Fixed width columns}\r
289 <<results='asis'>>=\r
290 align(tli.table) <- "|rr|lp{3cm}l|r|"\r
291 tli.table\r
292 @\r
293 \r
294 \newpage\r
295 \r
296 \subsection{Number of digits}\r
297 One number for all columns,\r
298 <<results='asis'>>=\r
299 display(tli.table)[c(2,6)] <- "f"\r
300 digits(tli.table) <- 3\r
301 tli.table\r
302 @\r
303 \r
304 \p\r
305 or one for each column, including the row names,\r
306 <<results='asis'>>=\r
307 digits(tli.table) <- 1:(ncol(tli)+1)\r
308 tli.table\r
309 @\r
310 \r
311 \p\r
312 or as a full matrix.\r
313 <<results='asis'>>=\r
314 digits(tli.table) <- matrix(0:4, nrow = 10, ncol = ncol(tli)+1)\r
315 tli.table\r
316 @\r
317 \r
318 \newpage\r
319 \r
320 \subsection{Suppress row/column names}\r
321 \subsubsection{Suppress row names}\r
322 <<results='asis'>>=\r
323 tli.table <- xtable(tli[1:10, ])\r
324 print(tli.table, include.rownames = FALSE)\r
325 @\r
326 \r
327 \p\r
328 If you want a vertical line on the left, you need to change the \code{align}\r
329 attribute.\r
330 <<results='asis'>>=\r
331 align(tli.table) <- "|r|r|lp{3cm}l|r|"\r
332 print(tli.table, include.rownames = FALSE)\r
333 @\r
334 \r
335 \p\r
336 Revert the alignment to what is was before.\r
337 <<>>=\r
338 align(tli.table) <- "|rr|lp{3cm}l|r|"\r
339 @\r
340 \r
341 \newpage\r
342 \r
343 \subsubsection{Suppress column names}\r
344 <<results='asis'>>=\r
345 print(tli.table, include.colnames = FALSE)\r
346 @\r
347 \r
348 \p\r
349 Note the doubled header lines which can be suppressed.\r
350 <<results='asis'>>=\r
351 print(tli.table, include.colnames = FALSE,\r
352       hline.after = c(0,nrow(tli.table)))\r
353 @\r
354 \r
355 \subsubsection{Suppress row and column names}\r
356 <<results='asis'>>=\r
357 print(tli.table, include.colnames = FALSE, include.rownames = FALSE)\r
358 @\r
359 \r
360 \newpage\r
361 \r
362 \subsection{Rotate row/column names}\r
363 The \code{rotate.rownames} and \code{rotate.colnames} arguments can be used to\r
364 rotate the row and/or column names. This requires \verb|\usepackage{rotating}|\r
365 in the \LaTeX\ preamble.\r
366 \r
367 <<results='asis'>>=\r
368 print(tli.table, rotate.rownames = TRUE, rotate.colnames = TRUE)\r
369 @\r
370 \r
371 \newpage\r
372 \r
373 \subsection{Horizontal lines}\r
374 \subsubsection{Line locations}\r
375 Use the \code{hline.after} argument to specify the position of the\r
376 horizontal lines.\r
377 \r
378 <<results='asis'>>=\r
379 print(xtable(anova(fm3)), hline.after = c(1))\r
380 @\r
381 \r
382 \subsubsection{Line styles}\r
383 Specifying \code{booktabs = TRUE} will generate three line types. By default,\r
384 when no value is given for \code{hline.after}, a \verb|\toprule| will be drawn\r
385 above the table, a \verb|\midrule| after the table headings and a\r
386 \verb|\bottomrule| below the table. This requires \verb|\usepackage{booktabs}|\r
387 in the \LaTeX\ preamble.\r
388 \r
389 \p\r
390 The top and bottom rules are slightly thicker than the mid rule. The thickness\r
391 of the lines can be set via the \LaTeX\ lengths \verb|\heavyrulewidth| and\r
392 \verb|\lightrulewidth|.\r
393 \r
394 <<results='asis'>>=\r
395 tli.table <- xtable(tli[1:10, ])\r
396 print(tli.table, include.rownames = FALSE, booktabs = TRUE)\r
397 @\r
398 \r
399 \p\r
400 If \code{hline.after} includes \code{-1}, a \verb|\toprule| will be\r
401 drawn above the table. If \code{hline.after} includes the number of\r
402 rows in the table, a \verb|\bottomrule| will be drawn below the\r
403 table. For any other values specified in \code{hline.after}, a\r
404 \verb|\midrule| will be drawn after that line of the table.\r
405 \r
406 \p\r
407 The following table has more than one \verb|\midrule|.\r
408 \r
409 <<results='asis'>>=\r
410 bktbs <- xtable(matrix(1:10, ncol = 2))\r
411 hlines <- c(-1, 0, 1, nrow(bktbs))\r
412 print(bktbs, booktabs = TRUE, hline.after = hlines)\r
413 @\r
414 \r
415 \subsection{Table level commands}\r
416 <<results='asis'>>=\r
417 print(xtable(anova(fm3)), size = "large")\r
418 @\r
419 \r
420 \p\r
421 <<results='asis'>>=\r
422 print(xtable(anova(fm3)), size = "\\setlength{\\tabcolsep}{12pt}")\r
423 @\r
424 \r
425 \subsection{Long tables}\r
426 Requires \verb|\usepackage{longtable}| in the \LaTeX\ preamble.\r
427 \r
428 <<results='asis'>>=\r
429 x <- matrix(rnorm(1000), ncol = 10)\r
430 x.big <- xtable(x, caption = "A \\code{longtable} spanning several pages")\r
431 print(x.big, hline.after=c(-1, 0), tabular.environment = "longtable")\r
432 @\r
433 \r
434 %% The column name alignment is off in the following example.\r
435 %% It needs some revision before exposing it. - CR, 7/2/2012\r
436 %\r
437 %% Tried to fix this and got some of the way, but \hlines are wrong\r
438 %% and first column is too wide. - DJS 4/10/2014\r
439 %% \subsubsection{Long tables with the header on each page}\r
440 %% The \code{add.to.row} argument can be used to display the header\r
441 %% for a long table on each page, and to add a "continued" footer\r
442 %% on all pages except the last page.\r
443 \r
444 %% \newcommand{\head}[1]{\centercell{\bfseries#1}}\r
445 \r
446 %% <<results='asis'>>=\r
447 %% x <- matrix(rnorm(1000), ncol = 10)\r
448 %% hdr <-  paste(paste("\\multicolumn{1}{c}{",1:9,"} & ", collapse = ""),\r
449 %%               "\\multicolumn{1}{c}{10}\\\\")\r
450 %% addtorow <- list()\r
451 %% addtorow$pos <- list()\r
452 %% addtorow$pos[[1]] <- c(0)\r
453 %% addtorow$command <- c(paste(\r
454 %%     hdr,\r
455 %%     "  \\hline \n",\r
456 %%     "  \\endhead \n",\r
457 %%     "  \\hline \n",\r
458 %%     "  {\\footnotesize Continued on next page} \n",\r
459 %%     "  \\endfoot \n",\r
460 %%     "  \\endlastfoot \n", sep = ""))\r
461 %% x.big2 <- xtable(x, label = "tabbig2", align = "lrrrrrrrrrr",\r
462 %%                  caption = "Example of longtable with the header on each page")\r
463 %% print(x.big2, tabular.environment = "longtable",\r
464 %%       include.rownames = FALSE, include.colnames = FALSE,\r
465 %%       add.to.row = addtorow)\r
466 %% @\r
467 \r
468 \newpage\r
469 \r
470 \subsection{Use of \code{add.to.row} argument}\r
471 The following frequency table has outer dimnames: \code{Grade3} and\r
472 \code{Grade6}.\r
473 \r
474 <<>>=\r
475 Grade3 <- c("A","B","B","A","B","C","C","D","A","B",\r
476             "C","C","C","D","B","B","D","C","C","D")\r
477 Grade6 <- c("A","A","A","B","B","B","B","B","C","C",\r
478             "A","C","C","C","D","D","D","D","D","D")\r
479 Cohort <- table(Grade3, Grade6)\r
480 Cohort\r
481 @\r
482 \r
483 \p\r
484 The default behavior of \code{print.xtable} is to strip outer dimnames.\r
485 <<results='asis'>>=\r
486 xtable(Cohort)\r
487 @\r
488 \r
489 \p\r
490 The desired column labels can be created using \code{add.to.row}, in this case\r
491 applying two commands to ``row number zero'' while suppressing the basic column\r
492 names.\r
493 \r
494 <<results='asis'>>=\r
495 addtorow <- list()\r
496 addtorow$pos <- list(0, 0)\r
497 addtorow$command <- c("& \\multicolumn{4}{c}{Grade 6} \\\\\n",\r
498                       "Grade 3 & A & B & C & D \\\\\n")\r
499 print(xtable(Cohort), add.to.row = addtorow, include.colnames = FALSE)\r
500 @\r
501 \r
502 \subsection{Sideways tables}\r
503 Requires \verb|\usepackage{rotating}| in the LaTeX\r
504 preamble.  Sideways tables can't be forced in place with the \code{[H]}\r
505 specifier, but you can use the \verb|\clearpage| command to get them\r
506 fairly nearby.\r
507 \r
508 <<results='asis'>>=\r
509 x <- x[1:30, ]\r
510 x.side <- xtable(x, caption = "A sideways table")\r
511 print(x.side, floating = TRUE, floating.environment = "sidewaystable")\r
512 @\r
513 \clearpage\r
514 \r
515 \subsection{Rescaled tables}\r
516 Specify a \code{scalebox} value to rescale the table.\r
517 <<results='asis'>>=\r
518 x <- x[1:20, ]\r
519 x.rescale <- xtable(x)\r
520 print(x.rescale, scalebox = 0.7)\r
521 @\r
522 \r
523 \subsection{Aligning fixed width columns}\r
524 Note that using specifications such as \verb|p{2cm}| always\r
525 produces a \textbf{left aligned} column. What if some other alignment\r
526 is desired?\r
527 \r
528 This is not really a problem with \pkg{xtable} but with the formatting\r
529 of tables with fixed width columns and different alignments using\r
530 standard \LaTeX.\r
531 \r
532 One solution is to use the \verb|array| package, defining new\r
533 column formats.\r
534 \r
535 \begin{verbatim}\r
536 \newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
537     \arraybackslash\hspace{0pt}}m{#1}}\r
538 \newcolumntype{C}[1]{>{\centering\let\newline\\\r
539     \arraybackslash\hspace{0pt}}m{#1}}\r
540 \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\r
541     \arraybackslash\hspace{0pt}}m{#1}}\r
542 \newcolumntype{P}[1]{>{\raggedright\tabularxbackslash}p{#1}}\r
543 \end{verbatim}\r
544 \r
545 These allow for very sophisticated cell formatting, namely\r
546 left-aligned, centred, or right-aligned text, with recognition of line\r
547 breaks for the first three new column types. If these lines are\r
548 included along with \verb|\usepackage{array}|, then the following\r
549 is possible.\r
550 \r
551 \newcolumntype{L}[1]{>{\raggedright\let\newline\\\r
552     \arraybackslash\hspace{0pt}}m{#1}}\r
553 \newcolumntype{C}[1]{>{\centering\let\newline\\\r
554     \arraybackslash\hspace{0pt}}m{#1}}\r
555 \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\r
556     \arraybackslash\hspace{0pt}}m{#1}}\r
557 \newcolumntype{P}[1]{>{\raggedright\tabularxbackslash}p{#1}}\r
558 \r
559 <<results='asis'>>=\r
560 df <- data.frame(name = c("A","B"), right = c(1.4, 34.6),\r
561                  left = c(1.4, 34.6), text = c("txt1","txt2"))\r
562 print(xtable(df, align = c("l", "|c", "|R{3cm}", "|L{3cm}", "| p{3cm}|")),\r
563       floating = FALSE, include.rownames = FALSE)\r
564 @\r
565 \r
566 \newpage\r
567 \r
568 \subsection{Table width}\r
569 The \code{tabularx} environment is for typesetting tables whose overall width is\r
570 fixed. The column alignment code \code{X} denotes columns that will be stretched\r
571 to achieve the desired table width. Requires \verb|\usepackage{tabularx}| in the\r
572 \LaTeX\ preamble.\r
573 \r
574 <<results='asis'>>=\r
575 df.width <- data.frame(One = c("item 1", "A"), Two = c("item 2", "B"),\r
576                        Three = c("item 3", "C"), Four = c("item 4", "D"))\r
577 x.width <- xtable(df.width)\r
578 align(x.width) <- "|l|X|l|l|l|"\r
579 print(x.width, tabular.environment = "tabularx", width = "\\textwidth")\r
580 @\r
581 \r
582 \section{Suppressing printing}\r
583 By default the \code{print} method will print the \LaTeX\ or HTML to standard\r
584 output and also return the character strings invisibly.  The printing to\r
585 standard output can be suppressed by specifying \code{print.results = FALSE}.\r
586 \r
587 <<>>=\r
588 x.out <- print(tli.table, print.results = FALSE)\r
589 @\r
590 \r
591 Formatted output can also be captured without printing with the\r
592 \code{toLatex} method.  This function returns an object of class\r
593 \code{"Latex"}.\r
594 \r
595 <<>>=\r
596 x.ltx <- toLatex(tli.table)\r
597 class(x.ltx)\r
598 x.ltx\r
599 @\r
600 \r
601 \newpage\r
602 \r
603 \section{Acknowledgements}\r
604 Most of the examples in this gallery are taken from the \pkg{xtable}\r
605 documentation. Two examples (\code{add.to.row} and `Aligning fixed width\r
606 columns') are from Stack Exchange.\r
607 \r
608 \section{Session information}\r
609 <<results='asis'>>=\r
610 toLatex(sessionInfo())\r
611 @\r
612 \r
613 \end{document}\r