I would like to display this in a cell of a flextable:
I’m working in an RMarkdown document that will Knit to Word. From my research, equations in flextables can either be rendered by writing in MathJax and use the flextable::compose()
with flextable::as_equation()
, or by writing the equation in markdown and using ftExtra::colformat_md()
. But it seems that neither full Latex or Markdown is supported here. I’ve tried a handful of ways to make this render, and I feel like I can either get multi-line cells or stacked fractions :
knitr::opts_chunk$set(echo = FALSE)
date <- c("date")
library(dplyr)
library(tidyr)
library(knitr)
library(flextable)
library(equatags)
library(officer)
library(ftExtra)
set_flextable_defaults(font.family="Times New Roman", hansi.family="Times New Roman")
FractionTable <- data.frame(
EqnColumn=c(
"n = {8 \over d^{2}}
n
\textrm{where} d = {\mu_2- \mu_1 \over \sigma}",
"n = \frac{8}{2}
nn
\textrm{where} d = {\mu_2- \mu_1 \over \sigma}",
""),
MarkdownColumn=c(
"$n = 8/d^{2}$ \
where $d= (\mu^_{1}-\mu^_{2})/ \sigma$",
"$n = 8/d^{2}$ \
where $$d= \frac{\mu^_{1}-\mu^_{2}}{sigma}$$",
"$n = 8/d^{2}$ \
where $d= \frac{2}{3}$")
)
FractionTable %>%
flextable()%>%
width(j=1:2, width=c(3,3)) %>%
compose( j="EqnColumn", value=as_paragraph(as_equation(EqnColumn)))%>%
colformat_md(j=2)
And this is the output:
The EqnColumn doesn’t seem to listen to any newline instruction I give it, and the MarkdownColumn can’t render fractions other than in-line text fractions.