I'm looking for an option to set the the font family and size of equations in a flextable
.
In general the font family and size of the table, rows and columns could be set via the sugar functions flextable::font
and flextable::fontsize
. However, both have no effect on the font family and size of equations neither in the HTML output nor when exporting to docx.
Running the reprex below gives the correct font family and size for the text column but not for the formula column.
library(flextable)
# Note: Running the reprex requires the `equatags` package.
# Also equatags::mathjax_install() must be executed
# to install necessary dependencies. See ?flextable::as_equation.
eqs <- c(
"(ax^2 + bx + c = 0)",
"a \\ne 0",
"x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}"
)
text = LETTERS[1:3]
df <- data.frame(text = text, formula = eqs)
df
#> text formula
#> 1 A (ax^2 + bx + c = 0)
#> 2 B a \\ne 0
#> 3 C x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}
ft <- flextable(df)
ft <- compose(
x = ft, j = "formula",
value = as_paragraph(as_equation(formula, width = 2))
)
ft <- width(ft, j = 2, width = 2)
ft <- fontsize(ft, size = 20, part = "all")
fn <- tempfile(fileext = ".docx")
save_as_docx(ft, path = fn)
if (FALSE) fs::file_show(fn) # Set to TRUE to show file
width
andheight
arguments as according to the docs these could be used to set thesize of the resulting equation
. But had no luck. Actually I don't understand how these arguments work as these had no effect on the final result. – Surcharge