Methods for the generic function toLatex
of package ``utils''
are provided for generating LaTeX representations
of matrices and flat contingency tables (see ftable
). Also a default method is defined
that coerces its first argument into a matrix and applies
the matrix method.
# S3 method for default
toLatex(object,…)# S3 method for matrix
toLatex(object,
show.titles=TRUE,
show.vars=FALSE,
show.xvar=show.vars,
show.yvar=show.vars,
digits=if(is.table(object)) 0 else getOption("digits"),
format="f",
useDcolumn=getOption("useDcolumn",TRUE),
colspec=if(useDcolumn)
paste("D{.}{",LaTeXdec,"}{",ddigits,"}",sep="")
else "r",
LaTeXdec=".",
ddigits=digits,
useBooktabs=getOption("useBooktabs",TRUE),
toprule=if(useBooktabs) "\\toprule" else "\\hline\\hline",
midrule=if(useBooktabs) "\\midrule" else "\\hline",
cmidrule=if(useBooktabs) "\\cmidrule" else "\\cline",
bottomrule=if(useBooktabs) "\\bottomrule" else "\\hline\\hline",
toLatex.escape.tex=getOption("toLatex.escape.tex",FALSE),
…)
# S3 method for data.frame
toLatex(object,
digits=getOption("digits"),
format="f",
useDcolumn=getOption("useDcolumn",TRUE),
numeric.colspec=if(useDcolumn)
paste("D{.}{",LaTeXdec,"}{",ddigits,"}",sep="")
else "r",
factor.colspec="l",
LaTeXdec=".",
ddigits=digits,
useBooktabs=getOption("useBooktabs",TRUE),
toprule=if(useBooktabs) "\\toprule" else "\\hline\\hline",
midrule=if(useBooktabs) "\\midrule" else "\\hline",
cmidrule=if(useBooktabs) "\\cmidrule" else "\\cline",
bottomrule=if(useBooktabs) "\\bottomrule" else "\\hline\\hline",
row.names=is.character(attr(object,"row.names")),
NAas="",
toLatex.escape.tex=getOption("toLatex.escape.tex",FALSE),
…)
# S3 method for ftable
toLatex(object,
show.titles=TRUE,
digits=if(is.integer(object)) 0 else getOption("digits"),
format=if(is.integer(object)) "d" else "f",
useDcolumn=getOption("useDcolumn",TRUE),
colspec=if(useDcolumn)
paste("D{.}{",LaTeXdec,"}{",ddigits,"}",sep="")
else "r",
LaTeXdec=".",
ddigits=digits,
useBooktabs=getOption("useBooktabs",TRUE),
toprule=if(useBooktabs) "\\toprule" else "\\hline\\hline",
midrule=if(useBooktabs) "\\midrule" else "\\hline\n",
cmidrule=if(useBooktabs) "\\cmidrule" else "\\cline",
bottomrule=if(useBooktabs) "\\bottomrule" else "\\hline\\hline",
extrarowsep = NULL,
toLatex.escape.tex=getOption("toLatex.escape.tex",FALSE),
…)
# S3 method for ftable_matrix
toLatex(object,
show.titles=TRUE,
digits=getOption("digits"),
format="f",
useDcolumn=getOption("useDcolumn",TRUE),
colspec=if(useDcolumn)
paste("D{.}{",LaTeXdec,"}{",ddigits,"}",sep="")
else "r",
LaTeXdec=".",
ddigits=digits,
useBooktabs=getOption("useBooktabs",TRUE),
toprule=if(useBooktabs) "\\toprule" else "\\hline\\hline",
midrule=if(useBooktabs) "\\midrule" else "\\hline",
cmidrule=if(useBooktabs) "\\cmidrule" else "\\cline",
bottomrule=if(useBooktabs) "\\bottomrule" else "\\hline\\hline",
compact=FALSE,
varontop,varinfront,
groupsep="3pt",
grouprule=midrule,
toLatex.escape.tex=getOption("toLatex.escape.tex",FALSE),
…)
an ftable
, a matrix or an object coercable into
a matrix.
logical, should variable names (in case of the
ftable
and table
methods)
or row and column names (in case of the matrix
method) be appear
in the LaTeX
code?
logical, should the names of the dimnames of object
be shown in the margins of the LaTeX tabular? Such names usually represent the
row and/or column variables of a two-dimensional table
.
number of significant digits.
character containing a format specifier, see format
.
logical, should the facilities of the dcolumn
LaTeX package be used?
Note that, if TRUE, you will need to include \usepackage{dcolumn}
in the preamble of your LaTeX document.
character, LaTeX table column format specifyer(s).
character, LaTeX table column format specifyer(s) for numeric vectors in the data frame.
character, LaTeX table column format specifyer(s) for factors in the data frame.
character, the decimal point in the final LaTeX output.
integer, digits after the decimal point.
logical, should the facilities of the booktabs
LaTeX package be used?
Note that, if TRUE, you will need to include \usepackage{booktabs}
in the preamble of your LaTeX document.
character string, TeX code that determines the appearance of the top border of the LaTeX tabular
environment.
character string, TeX code that determines how coefficients and summary statistics are
separated in the LaTeX tabular
environment.
character string, TeX code that determines the appearance of rules under section headings.
character string, TeX code that determines the appearance of the bottom border of the LaTeX tabular
environment.
character string, extra code to be inserted between the column titles and the
table body produced by toLatex
.
logical, if TRUE
, extra column space between sub-tables
is suppressed. Defaults to FALSE
logical, whether names of column variables should appear on top of factor levels
logical, whether names of row variables should appear in front of factor levels
character string, containing a TeX length; extra
vertical space inserted between sub-tables, unless compact
is TRUE
.
character string, TeX code that determines how sub-table headings are embellished.
logical, whether row names should be included in exported LaTeX code.
character string, how missing values should be represented.
logical, should symbols \$, \_, and \^ be escaped with backslashes?
further argument, currently ignored.
# NOT RUN {
toLatex(diag(5))
toLatex(ftable(UCBAdmissions))
toLatex(rbind(
ftable(margin.table(UCBAdmissions,c(2,1))),
ftable(margin.table(UCBAdmissions,c(3,1)))
))
# }
Run the code above in your browser using DataLab