This function generates a LaTeX table from a data frame using the kableExtra package, with options to adjust the table size, apply striped styling, and set the table orientation to landscape or portrait mode.

kable_table(
  data,
  caption,
  scl = 0.75,
  row.names = FALSE,
  striped = TRUE,
  landscape = TRUE,
  table_size = "medium",
  digits = 3,
  latex_options = c("striped"),
  format = "latex"
)

Arguments

data

A data frame to be displayed in the table.

caption

A character string for the table caption.

scl

A numeric value to scale the table size. Defaults to 0.75.

row.names

Logical, whether to include row names in the table. Defaults to FALSE.

striped

Logical, whether to apply striped styling to the table. Defaults to TRUE.

landscape

Logical, whether to rotate the table to landscape mode. Defaults to TRUE.

table_size

A character string for adjusting the overall size of the table. Options include "small", "medium", "large". Defaults to "medium".

digits

An integer specifying the number of decimal places for numeric values. Defaults to 3.

latex_options

A character vector for specifying additional LaTeX styling options. Defaults to c("striped").

format

either latex or html

Value

A LaTeX table generated with kableExtra, ready for inclusion in an RMarkdown or LaTeX document.

Examples

data <- mtcars[1:5, 1:5]
kable_table(data, caption = "Sample Table", scl = 0.8, row.names = TRUE, striped = TRUE, landscape = FALSE, table_size = "large")
#> 
#> Attaching package: ‘kableExtra’
#> The following object is masked from ‘package:dplyr’:
#> 
#>     group_rows
#> \begin{table}
#> \centering\centering
#> \caption{Sample Table}
#> \centering
#> \begin{tabular}[t]{>{}lrrrrr}
#> \toprule
#>   & mpg & cyl & disp & hp & drat\\
#> \midrule
#> \cellcolor{gray!22}{\textbf{\cellcolor{gray!10}{Mazda RX4}}} & \cellcolor{gray!22}{\cellcolor{gray!10}{21.0}} & \cellcolor{gray!22}{\cellcolor{gray!10}{6}} & \cellcolor{gray!22}{\cellcolor{gray!10}{160}} & \cellcolor{gray!22}{\cellcolor{gray!10}{110}} & \cellcolor{gray!22}{\cellcolor{gray!10}{3.90}}\\
#> \textbf{Mazda RX4 Wag} & 21.0 & 6 & 160 & 110 & 3.90\\
#> \cellcolor{gray!22}{\textbf{\cellcolor{gray!10}{Datsun 710}}} & \cellcolor{gray!22}{\cellcolor{gray!10}{22.8}} & \cellcolor{gray!22}{\cellcolor{gray!10}{4}} & \cellcolor{gray!22}{\cellcolor{gray!10}{108}} & \cellcolor{gray!22}{\cellcolor{gray!10}{93}} & \cellcolor{gray!22}{\cellcolor{gray!10}{3.85}}\\
#> \textbf{Hornet 4 Drive} & 21.4 & 6 & 258 & 110 & 3.08\\
#> \cellcolor{gray!22}{\textbf{\cellcolor{gray!10}{Hornet Sportabout}}} & \cellcolor{gray!22}{\cellcolor{gray!10}{18.7}} & \cellcolor{gray!22}{\cellcolor{gray!10}{8}} & \cellcolor{gray!22}{\cellcolor{gray!10}{360}} & \cellcolor{gray!22}{\cellcolor{gray!10}{175}} & \cellcolor{gray!22}{\cellcolor{gray!10}{3.15}}\\
#> \bottomrule
#> \end{tabular}
#> \end{table}