Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_equation

equation chunk


Description

This function is used to insert equations into flextable with function compose(). It should be used inside a call to as_paragraph().

To use this function, package 'equatags' is required; also equatags::mathjax_install() must be executed only once to install necessary dependencies.

Usage

as_equation(x, width = 1, height = 0.2, unit = "in")

Arguments

x

values containing the 'MathJax' equations

width, height

size of the resulting equation in inches

unit

unit for width and height, one of "in", "cm", "mm".

See Also

Other chunk elements for paragraph: as_bracket(), as_b(), as_chunk(), as_highlight(), as_image(), as_i(), as_sub(), as_sup(), colorize(), gg_chunk(), hyperlink_text(), linerange(), lollipop(), minibar(), plot_chunk()

Examples

library(flextable)
if(require("equatags") && mathjax_available()){

eqs <- c(
  "(ax^2 + bx + c = 0)",
  "a \\ne 0",
  "x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}")
df <- data.frame(formula = eqs)
df


ft <- flextable(df)
ft <- compose(
  x = ft, j = "formula",
  value = as_paragraph(as_equation(formula, width = 2, height = .5)))
ft <- align(ft, align = "center", part = "all")
ft <- width(ft, width = 2)
ft

}

flextable

Functions for Tabular Reporting

v0.6.10
GPL-3
Authors
David Gohel [aut, cre], Clementine Jager [ctb], Quentin Fazilleau [ctb], Maxim Nazarov [ctb] (rmarkdown for docx output), Titouan Robert [ctb], Michael Barrowman [ctb] (inline footnotes), Atsushi Yasumoto [ctb] (support for bookdown cross reference), Paul Julian [ctb] (support for gam objects)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.