Search code examples
rlatexr-markdownreporters

How can I convert a html table in Rmarkdown into Latex in order to output in a pdf?


I'm working on an RMarkdown pdf document and am trying to convert a table formatted in html using the FlexTable object of the RepoRters package and want to convert it into latex so that I can ouput the table into a pdf.

Is there a way to do this?

Thanks! Rafael


Solution

  • This is an example that works on my machine. Be sure to include the header-includes block in the YAML content.

    ---
    title: "lazyWeave Example"
    output: pdf_document
    header-includes:
       - \usepackage{xcolor}
       - \usepackage{graphicx}
       - \usepackage{colortbl}
    ---
    
    After running `install.packages("lazyWeave")` the following should produce the desired table.
    
    ```{r}
    library(lazyWeave)
    options(lazyReportFormat = "latex")
    ```
    
    ```{r, results='asis'}
    lazy.matrix(mtcars[1:10, ],
                rcol = c(TRUE, FALSE),
                usecol = "lightgray")
    ```