rmathr-markdownflextable

Is it possible to include $math$ inside flextables?


I would like to have some fancy equations within a nicely formatted table. Is it possible to use flextable to achieve this?

library(flextable)
df <- data.frame(FancyMath= c("$A^{-1}$", "$A = pi~r^2$"))
flextable(df)

The $ $ notation is not creating Math-style writing as I would expect. Thanks!


Solution

  • The answer depends on how your question is understood:

    1. Is it possible to include $math$ inside flextables, i.e., math with LaTeX syntax, $math$?

    No, it's not possible.

    1. Is it possible to include "math" inside flextables?

    Yes, what you are looking for is:

    install.packages("equatags")
    library(flextable)
    
    df <- data.frame(FancyMath = c("A^{-1}", "A = pi~r^2")) # Note `$` signs are omitted
    flextable(df) |>
      compose(j = "FancyMath", value = as_paragraph(as_equation(FancyMath)))