rpdfr-markdownsummarytools

Aligning summarytools tables in Rmarkdown


How do you move summarytools tables in Rmarkdown? For example, how do you move the following table to the left for PDFs?

title: "Moving summarytools tables"
date: "`r Sys.Date()`"
output: pdf_document
library(summarytools)
summarytools::freq(cars$speed,headings=FALSE,report.nas = FALSE,cumul=FALSE)

Solution

  • Small workaround. Convert the summarytools to data.frame and then to flextable

    First adjust knitr options and load necessary packages

    ```{r, setup}
    
    knitr::opts_chunk$set(ft.align = "right")
    
    if(!require(pacman)) install.packages("pacman")
    
    p_load(summarytools, flextable)
    
    ``` 
    

    Then you can do the table

    ```{r}
    
    flextable(as.data.frame(summarytools::freq(cars$speed,headings=FALSE,report.nas = FALSE,cumul=FALSE)))
    
    ```