latexTable | R Documentation |
latexTable()
takes a single matrix or tibble, mat
. By
default, it returns a LaTeX macro that creates a well-formatted LaTeX
table.
latexTable( mat, SE_table = TRUE, headerFooter = TRUE, commandName = "myTable", callCommand = TRUE, label = commandName, floatPlacement = "p", landscape = if (SE_table) ncol(mat)/2 >= 6 else ncol(mat) >= 6, starredFloat = FALSE, horizOffset = "-0in", rowNames = rownames(mat), footerRows = lt_footer(), colNames = lt_colNames_default(), colNameExpand = FALSE, extraRowHeight = if (SE_table) "2pt" else "4pt", spacerColumns = lt_spacerColumns_default(), spacerColumnsWidth = ".67em", spacerRows = NULL, spacerRowsHeight = ".15in", tabColSep = "2.75pt", spaceBetweenColNameRows = "-.025in", columnTierSeparator = " ", printCaption = TRUE, caption = paste0(label, " caption goes here."), captionMargins = NULL, formatNumbers = TRUE, decimalPlaces = 2, SE_fontSizeString = "\\fontsize{10.3bp}{10.3bp}\\selectfont", NA_text = "", clipboard = FALSE )
mat |
Matrix or tibble of numbers to be displayed in a LaTeX table. |
SE_table |
Logical variable that indicates whether |
headerFooter |
Logical variable. If |
commandName |
A string. It is the name of the macro that produces the
LaTeX table (if |
callCommand |
Logical variable. Should the last line of the
|
label |
A string. Specifies the LaTeX label for a table. It is not printed
anywhere in the table, but references to the figure in
your LaTeX document (for example, references created by |
floatPlacement |
Character vector of length\NB1. Acceptable values
are |
landscape |
Logical variable. Determines whether the table is printed
in landscape or in portrait mode. Affects the output only if if
|
starredFloat |
Logical variable that indicates whether the LaTeX
table should be specified with |
horizOffset |
A string that specifies a LaTeX length, e.g., ".25in".
When the LaTeX code produced by |
rowNames |
Character vector of labels for the rows in |
footerRows |
List, object that can be coerced to a list, or a function
that creates a list. Each element in the list is a character vector that
specifies entries for a row of the footer, or a function that creates
such a character vector. The default is
\linkIntlt_footer, which typically provides a "Number of observations"
row. If a model is of class "lm," it will also provide an
R2 and
"Std. error of regression" row. |
colNames |
List, or object that can be coerced to a list, of column
headings. Typically, each element in the list is a character vector, and
the elements of the character vector specify the names of the table's
columns. |
colNameExpand |
Logical variable. By default, an entry of '' in a
|
extraRowHeight |
A string that specifies a length that LaTeX
recognizes, e.g., '2pt' or '.25in'. The |
spacerColumns |
A vector of integers. Specifies columns in
|
spacerColumnsWidth |
Either a single string of a recognizable LaTeX
length (e.g., '.5em') or a character vector indicating the width of each
spacer column. Has no effect unless |
spacerRows |
A vector of integers. After each row in |
spacerRowsHeight |
A string that specifies a recognizable LaTeX length, e.g., ".15in". |
tabColSep |
Character vector indicating a length that LaTeX recognizes,
e.g., ".25in". The |
spaceBetweenColNameRows |
String specifying a LaTeX length, e.g., "-.025in" (the default). When column names are to be split across multiple rows, a vertical space of this length will be inserted between the rows. |
columnTierSeparator |
A string. In the LaTeX code generated by
|
printCaption |
Logical variable. |
caption |
A string. It can include LaTeX commands, e.g., "\\textitResults from a minimal specification." It can also include references to other labeled parts of your LaTeX document, e.g., "\\autorefSomeFigure". See the examples. |
captionMargins |
A vector of two strings that specify the margins of
the caption. The strings should be LaTeX lengths, e.g., ".25in" or ".67em".
By default, |
formatNumbers |
Logical variable,
If |
decimalPlaces |
Integer. If |
SE_fontSizeString |
A string. Indicates how standard errors are to be
formatted when |
NA_text |
A string. |
clipboard |
Logical variable. Copy entire output to clipboard.
Useful if you want to paste the output directly into a |
An object of classes latexTable
and character
. The
returned object is a vector of strings of LaTeX code; each string is a line
in a LaTeX macro that can create a table.
\indent There is one small exception. If callCommand
is
TRUE
, the last line is not part of the macro; instead, it calls the
macro, thereby telling LaTeX to display the table. For example, if
commandName
and label
are myTable
, and if
callCommand
is TRUE
, the last line of the returned object is
\mytable{p}
.
Required LaTeX packages. The LaTeX code produced by the
latexTable
makes use of capabilities provided by the booktabs
,
caption
, float
, numprint
, and ragged2e
LaTeX
packages—and, for landscaped tables, the pdflscape
\NBpackage. If
you haven't installed those LaTeX packages, you won't be able to render the
tables produced by latexTable
.
\indent The LaTeX code produced by latexTable
also makes use of
capabilities provided by the array
and afterpage
LaTeX
packages—but these packages are included
in every LaTeX distribution.
Changes from pre-release versions:
The names of some arguments have
changed slightly since the pre-release versions of this function. They have
been changed to enforce consistency: camelCase is used for all arguments,
and every acronym is followed by an underscore (_) character. We thus have
SE_table
instead of SEtable
, tabColSep
instead of
tabcolsep
, and so\NBon.
The hspace
argument has been renamed to horizOffset
.
Some default arguments have changed. In particular, the default
spacerColumns
argument is no longer NULL
. Instead, the
default is to insert spacer columns in appropriate places. See documentation
of the spacerColumns
argument for details.
Other functions for making tables: \linkIntregTable,
\linkIntlatexTablePDF. See also the Building better tables in less time
and Using latexTable()
with R Markdown and Rnw documents
vignettes.
data(iris) lm1 <- lm(Sepal.Length ~ Petal.Length, data = iris) lm2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris) lm3 <- lm(Sepal.Length ~ Petal.Length * Petal.Width, data = iris) rT1 <- regTable(list(lm1, lm2, lm3)) latexTable(rT1) latexTable(rT1, SE_table = FALSE, colNames = lt_colNumbers()) lt2 <- latexTable( mat = rT1, colNames = list(qw("model model model"), qw("1 2 3"))) ## Not run: lt3 <- latexTable( mat = rT1, colNames = lt_colNumbers(), rowNames = c( "Intercept", "Petal length", "Petal width", "Petal length $\\times$ petal width"), footerRows = list(lt_nobsRow(), lt_rSquaredRow()), commandName = 'mainEstimates', caption = "Each entry is an estimate or a standard error from a separate OLS regression.") lt4 <- update( lt3, commandName = 'myEstimates', # change name of LaTeX macro spacerRows = 1, # add vertical space after intercept row footerRows = list( c("My first footer row", "a", "b", "c"), c("My second footer row", "Lorem", "ipsum", "dolor") )) ## End(Not run) # You can pass a previously created list to the "footerRows" argument. To # store functions in that list, use alist(): footerList <- alist(lt_rSquaredRow, lt_SER_row) latexTable(rT1, footerRows = footerList)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.