
Create an output-independent, formatted kable table
Source:R/create_knitr_table.R
create_knitr_table.RdWrapper around knitr::kable() with sensible defaults
for alignment, borders, and formatting, compatible with HTML and LaTeX
output formats.
Usage
create_knitr_table(
data_table,
digits = NULL,
caption = NA,
col.names = NULL,
col_width = NULL,
width_unit = "cm",
col_align = NULL,
border_right_cols = NULL,
bold_cols = NULL,
bootstrap_options = c("striped", "hover", "condensed"),
latex_options = NULL,
output_format = NULL,
keep_pdf = FALSE,
latex_header_includes = c("\\usepackage[magyar]{babel}",
"\\usepackage[utf8]{inputenc}")
)Arguments
- data_table
A
data.frame, tibble, named matrix, orknitr_kableobject.- digits
Number of digits to display for numeric variables. Defaults to
getOption("digits").- caption
Optional table caption. Defaults to
NA(no caption).- col.names
Column names for the table. If
NULL, usesnames(data_table).- col_width
Numeric vector of column widths. If
NULL, defaults to 2 for the first column and equal share for the rest.- width_unit
Character. Unit for column widths (default
"cm").- col_align
Column alignment. Defaults to
"l"for the first column,"c"for others.- border_right_cols
Logical vector for right-hand column borders. Defaults to
TRUEfor the first column,FALSEotherwise.- bold_cols
Logical vector. If
TRUE, makes the column bold. Defaults to allFALSE.- bootstrap_options
Passed to
kableExtra::kable_styling()for HTML output. Defaults toc("striped", "hover", "condensed").- latex_options
Passed to
kableExtra::kable_styling()for LaTeX output. Defaults toc("scale_down", "striped").- output_format
Character:
"html","latex", or"image". IfNULL, auto-detects from knitr options.- keep_pdf
Logical. Only relevant for
output_format = "image". Defaults toFALSE.- latex_header_includes
Character vector of LaTeX headers to include. Defaults to
c("\\usepackage[magyar]{babel}", "\\usepackage[utf8]{inputenc}").