Skip to content
Thomas J. Brailey edited this page Jun 6, 2020 · 11 revisions

Overview

  • One can easily embed LaTeX tables within an R-Markdown document. LaTeX tables are useful when presenting summary statistics and regression tables.

Packages

  • There are a number of packages that allow for LaTeX outputs:
  • An example using knitr::kable and kableExtra. These packages allow you to manipulate and visualize tables in one continuous chunk:
my_df %>% 
  dplyr::select(-my_unwanted_var) %>%
  dplyr::summarize_all(funs(round(mean(.), 2))) %>% 
  knitr::kable("latex", 
          booktabs = T, 
          escape = T,
          col.names = linebreak(c("Column Name 1", 
                                  "Column Name 2"), 
                                align = "c"),
          caption = "My Title (2020)",
          linesep = "",
          align = rep("c", 2)) %>% 
  kableExtra::add_footnote("My footnote") %>% 
  kableExtra::column_spec(1:2, width = "20em") %>%
  kableExtra::kable_styling(font_size = 10) 

Interactive tables

  • As mentioned in the R-Notebook documentation, the DT package allows you to create interactive tables where you can subset and search for specific entries. An example code is shown below:
# Example 
DT::datatable(my_data, options = list(pageLength = 10))
  • Information for DT specifically can be found here.
  • More information on htmlwidgets for R-Markdown can be found here.

Clone this wiki locally