Description Usage Arguments Details Value Author(s) Examples
Print the LaTeX code associated with the supplied data table. The applied output format attempts to adhere to the design recommendations for tables in United States Geological Survey (USGS) publications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
d |
'data.frame' or 'matrix'. Data table to print. |
colheadings |
'character' vector, 'matrix', or 'data.frame'.
Column headings.
For table objects, rows represent layers of headings (stacked headings).
The number of columns (or vector length) must equal the number of columns in argument |
align |
'character' vector.
Column alignment.
Specify |
digits |
'integer' vector. Number of digits to display in the corresponding columns. |
label |
'character' string.
LaTeX label anchor.
Specifying this argument allows you to easily reference the table within the LaTeX document.
For example, when |
title |
'character' string. Table caption |
headnotes |
'character' string. Label placed below the table caption to provide information pertaining to the caption, to the table as a whole, or to the column headings. |
footnotes |
'character' string. Label placed at the end of the table to provide explanations of individual entries in the table. |
nrec |
'integer' vector of length 1 or 2, value is recycled as necessary. Maximum number of records to show on the first page, and every subsequent page, respectively. |
hline |
'integer' vector.
Numbers between 1 and |
na |
'character' string. Value to be used for missing values in table entries. |
rm_dup |
'integer' count.
End value of a sequence of column indexes |
landscape |
'logical' flag.
If true, conforming PDF viewers will display the table in landscape orientation.
This option requires |
... |
Additional arguments to be passed to the |
Requires \usepackage{caption}
, \usepackage{booktabs}
,
\usepackage{makecell}
, \usepackage{multirow}
, and
\usepackage{siunitx}
in the LaTeX preamble.
Invisible NULL
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | d <- datasets::iris[, c(5, 1:4)]
colheadings <- rbind(c("Species \\\\ type", rep("Sepal", 2), rep("Petal", 2)),
c("", rep(c("Length", "Width"), 2)))
align <- c("l", "c", "c", "c", "c")
digits <- c(0, 1, 1, 1, 1)
title <- "Measurements of sepal length and width and petal
length and width for three species of Iris flower."
headnotes <- "\\textbf{Iris Species}: setosa, versicolor, and virginica.
\\textbf{Abbreviations}: cm, centimeters"
levels(d[[1]]) <- sprintf("%s\\footnotemark[%d]", levels(d[[1]]), 1:3)
footnotes <- sprintf("\\footnotemark[%d] Common name is %s iris.",
1:3, c("Wild Flag", "Blue Flag", "Virginia"))
footnotes <- paste(footnotes, collapse = "\\\\")
hline <- utils::tail(which(!duplicated(d[[1]])), -1) - 1L
PrintTable(d, colheadings, align, digits, title = title,
headnotes = headnotes, footnotes = footnotes,
hline = hline, nrec = c(41, 42), rm_dup = 1)
## Not run:
sink("test-table.tex")
cat("\\documentclass{article}",
"\\usepackage{geometry}",
"\\usepackage[labelsep = period, labelfont = bf]{caption}",
"\\usepackage{siunitx}",
"\\sisetup{input-ignore = {,}, input-decimal-markers = {.},",
" group-separator = {,}, group-minimum-digits = 4}",
"\\usepackage{booktabs}",
"\\usepackage{makecell}",
"\\usepackage{multirow}",
"\\usepackage[pdftex]{lscape}",
"\\makeatletter",
"\\setlength{\\@fptop}{0pt}",
"\\makeatother",
"\\begin{document}", sep = "\n")
PrintTable(d, colheadings, align, digits, title = title,
headnotes = headnotes, footnotes = footnotes,
hline = hline, nrec = c(41, 42), rm_dup = 1)
cat("\\clearpage\n")
PrintTable(datasets::CO2[, c(2, 3, 1, 4, 5)],
digits = c(0, 0, 0, 0, 1),
title = "Carbon dioxide uptake in grass plants.",
nrec = 45, rm_dup = 3)
cat("\\clearpage\n")
digits <- c(1, 0, 1, 0, 2, 3, 2, 0, 0, 0, 0)
PrintTable(datasets::mtcars, digits = digits,
title = "Motor trend car road tests.",
landscape = TRUE, include.rownames = TRUE)
cat("\\clearpage\n")
x <- c(1.2, 1.23, 1121.2, 184, NA, pi, 0.4)
d <- data.frame(matrix(rep(x, 4), ncol = 4),
stringsAsFactors = TRUE)
d[, 1] <- prettyNum(d[, 1])
d[, 4] <- formatC(d[, 4], digits = 2, format = "e")
colheadings <- paste("Wide heading", 1:ncol(d))
align <- c("S", "S",
"S[round-mode = places, round-precision = 2]",
"S[scientific-notation = true, table-format = 1.2e+1]")
PrintTable(d, colheadings, align)
cat("\\end{document}\n")
sink()
tinytex::pdflatex("test-table.tex") # requires LaTeX
system("open test-table.pdf")
file.remove("test-table.tex", "test-table.pdf")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.