Create some test data

library(tidyverse)
library(knitr)
library(kableExtra)
simple_df_one_column <- data.frame(
  text = paste0('TEXT ', seq(1, 6))
)

simple_df_one_column_math <- data.frame(
  math = paste0('$\\text{Math:} x = ', seq(1, 6), '$ TEXT')
)

simple_df_multi_columns <- data.frame(
  text = paste0('TEXT ', seq(1, 6)),
  desc = paste0('DESCRIPTION ', seq(1, 6))
)

simple_df_multi_columns_math <- data.frame(
  text = paste0('TEXT ', seq(1, 6)),
  math = paste0('$\\text{Math:} x = ', seq(1, 6), '$ TEXT')
)

simple_df_longtable_one_column <- data.frame(
  text = paste0('TEXT ', seq(1, 50))
)

simple_df_longtable_one_column_math <- data.frame(
  math = paste0('$\\text{Math:} x = ', seq(1, 50), '$ TEXT')
)

simple_df_longtable_multi_columns <- data.frame(
  text = paste0('TEXT ', seq(1, 50)),
  desc = paste0('DESCRIPTION ', seq(1, 50))
)

simple_df_longtable_multi_columns_math <- data.frame(
  text = paste0('TEXT ', seq(1, 50)),
  math = paste0('$\\text{Math:} x = ', seq(1, 50), '$ TEXT')
)

Simple Table with One Column

simple_df_one_column %>%
  kable("latex", escape = F, booktabs = T) %>%
  kable_styling(latex_options = c('striped'))
simple_df_one_column %>%
  kable("latex", escape = F, booktabs = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped'))

Simple Table with One Column and Math

simple_df_one_column_math %>%
  kable("latex", escape = F, booktabs = T) %>%
  kable_styling(latex_options = c('striped'))
simple_df_one_column_math %>%
  kable("latex", escape = F, booktabs = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped'))

Simple Table with Multi Columns

simple_df_multi_columns %>%
  kable("latex", escape = F, booktabs = T) %>%
  kable_styling(latex_options = c('striped'))
simple_df_multi_columns %>%
  kable("latex", escape = F, booktabs = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped'))

Simple Table with Multi Columns and Math

simple_df_multi_columns_math %>%
  kable("latex", escape = F, booktabs = T) %>%
  kable_styling(latex_options = c('striped'))
simple_df_multi_columns_math %>%
  kable("latex", escape = F, booktabs = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped'))

Simple Long Table with One Column

simple_df_longtable_one_column %>%
  kable("latex", caption = 'Long Table with One Column',
        escape = F, booktabs = T, longtable = T) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))
simple_df_longtable_one_column %>%
  kable("latex", caption = 'Long Table with One Column without Colnames',
        escape = F, booktabs = T, longtable = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))

Simple Long Table with One Column and Math

simple_df_longtable_one_column_math %>%
  kable("latex", caption = 'Long Table with One Column',
        escape = F, booktabs = T, longtable = T) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))
simple_df_longtable_one_column_math %>%
  kable("latex", caption = 'Long Table with One Column without Colnames',
        escape = F, booktabs = T, longtable = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))

Simple Long Table with Multi Columns

simple_df_longtable_multi_columns %>%
  kable("latex", caption = 'Long Table with One Column',
        escape = F, booktabs = T, longtable = T) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))
simple_df_longtable_multi_columns %>%
  kable("latex", caption = 'Long Table with One Column without Colnames',
        escape = F, booktabs = T, longtable = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))

Simple Long Table with Multi Columns and Math

simple_df_longtable_multi_columns_math %>%
  kable("latex", caption = 'Long Table with One Column',
        escape = F, booktabs = T, longtable = T) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))
simple_df_longtable_multi_columns_math %>%
  kable("latex", caption = 'Long Table with One Column without Colnames',
        escape = F, booktabs = T, longtable = T, col.names = NULL) %>%
  kable_styling(latex_options = c('striped', 'repeat_header'))


haozhu233/kableExtra documentation built on April 13, 2024, 6:49 p.m.