Search code examples
htmllatexkableextraquartoreveal.js

latex equations in tables with quarto/revealjs?


I am using quarto with revealjs to make a presentation in rstudio. Code is as follows

---
title: "table_latex"
format: revealjs
---

## Quarto


```{r}
library(readr)
tbl1 <- read_csv("table.csv")
library(knitr)
library(kableExtra) 

kbl(tbl1, escape = FALSE) %>%
  kable_classic(full_width = F) %>%
    kable_styling(font_size = 24) %>%
      row_spec(2, color = "lightgray", background = "darkred")
```

table.csv is something like this:

var, val
$a$, 1
$b$, 2
$c$, 3

The output within rstudio looks fine, the rendered html looks bad. enter image description here

Why the output is not the same?


Solution

  • I am not sure why your approach is not working, but it seems if you save the table in a variable and then cat() it along with results: asis, it works!! (Not sure why this workaround is needed though).

    ---
    title: "table_latex"
    format: revealjs
    ---
    
    ## Quarto
    
    
    ```{r}
    library(readr)
    library(kableExtra) 
    
    tbl1 <- read_csv("table.csv")
    ```
    
    
    ```{r}
    #| results: asis
    tab <- kbl(tbl1) %>%
      kable_classic(full_width = F) %>%
        kable_styling(font_size = 24) %>%
          row_spec(2, color = "lightgray", background = "darkred")
    
    cat(tab)
    ```
    
    

    math equation in kableExtra table