Search code examples
rr-markdownsuperscript

Is it possible to generate superscript in HTML from a string variable using RMarkdown?


Is there a way to create superscript in rmarkdown in string?

If I have a string - acceleration", I want to include the unit next to like "acceleration (m/sec^2)" so that when it's rendered to HTML table column names, it should show up as

acceleration (m/sec2)

All column names should have their units next to the name, that's why I'm trying to do this.

I tried:

names(vars) <- c("", ...,"acceleration m/sec \\textsuperscript{2}")
names(vars) <- c("", ...,"acceleration $m/sec^2$)

and other variations.. but didn't work. I keep getting error on these when I knitr. Is it possible, so that when I render it to html that it produces the superscript correctly?


Solution

  • The markdown notation is ^.^ and ~.~ to write super and subscripts.

    testdata <- mtcars[1:2]
    names(testdata) <- c("", "acceleration (m/sec^2^)")
    knitr::kable(testdata)
    

    enter image description here