This function takes a data frame or matrix with column names and outputs a lightly-formatted LaTeX table version of that data frame.
dftoLaTeX(
data,
file = NA,
fit.page = NA,
frag = TRUE,
title = NA,
note = NA,
note.align = "l",
anchor = NA,
align = NA,
row.names = FALSE,
no.escape = NA
)
Data set; accepts any format with column names.
Saves the completed table to LaTeX with this filepath.
uses a LaTeX resizebox to force the table to a certain width. Often '\textwidth'
.
Set to TRUE to produce only the LaTeX table itself, or FALSE to produce a fully buildable LaTeX. Defaults to TRUE.
Character variable with the title of the table. Set to NA
to omit.
Table note to go after the last row of the table.
Set the alignment for the multi-column table note. Usually "l", but if you have a long note you might want to set it with "p"
Character variable to be used to set a label tag for the table.
Character variable with standard LaTeX formatting for alignment, for example 'lccc'
. You can also use this to force column widths with p
in standard LaTeX style. Defaults to the first column being left-aligned and all others centered. Be sure to escape special characters, in particular backslashes (i.e. p{.25\\textwidth}
instead of p{.25\textwidth}
).
Flag determining whether or not the row names should be included in the table. Defaults to FALSE
.
Vector of column indices for which special characters should not be escaped (perhaps they include markup text of their own).
This function is designed to feed LaTeX versions of variable tables to vtable()
, sumtable()
, and labeltable()
.
Multi-column cells are supported. Wrap the cell's contents in a multicolumn
tag as normal, and then fill in any cells that need to be deleted to make room for the multi-column cell with "DELETECELL". Or use the MULTICOL syntax of dftoHTML
, that works too.
If the first column and row begins with the text "HEADERROW", then the first row will be put above the column names.
df <- data.frame(var1 = 1:4,var2=5:8,var3=c('A','B','C','D'),
var4=as.factor(c('A','B','C','C')),var5=c(TRUE,TRUE,FALSE,FALSE))
dftoLaTeX(df, align = 'ccccc')
#> [1] "\\begin{table}[!htbp] \\centering \\renewcommand*{\\arraystretch}{1.1}\n\\begin{tabular}{ccccc}\n\\hline\n\\hline\nvar1 & var2 & var3 & var4 & var5 \\\\ \n\\hline\n1 & 5 & A & A & TRUE \\\\ \n2 & 6 & B & B & TRUE \\\\ \n3 & 7 & C & C & FALSE \\\\ \n4 & 8 & D & C & FALSE\\\\ \n\\hline\n\\hline\n\\end{tabular}\n\\end{table}\n"