How to format colnames text in tableHTML package?

99 Views Asked by At

HTML is working fine in the rownames as well as in the caption and in the footer. Contrary to intuition in the colnames it's not working. How could I achieve equivalent formatting within the colnames?

mx <- matrix(1:9, nrow = 3, 
             dimnames = list(c("<i>&alpha;<sub>i</sub></i>", 
                               "<i>&beta;<sub>i</sub></i>", 
                               "<i>&gamma;<sub>i</sub></i>"),
                             c("<i>&Phi;<sub>i</sub></i>", 
                               "<i>&Sigma;<sub>i</sub></i>", 
                               "<i>&Tau;<sub>i</sub></i>")))
library(tableHTML)
tableHTML(mx
          , widths = rep(20, 4)
          , border = 0
          , rownames = TRUE
          , caption = "<b>Table 1: <i>&Phi;<sub>i</sub></i> and their <i>&Sigma;<sub>i</sub></i> and <i>&Tau;<sub>i</sub></i></b>"
          , footer = "<i>Note: </i><i>&Phi;<sub>i</sub></i>. Do re mi fa so la."
          , collapse = "separate"
          , spacing = "5px"
          , theme = 'scientific'
)

enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER

tableHTML will escape > and < by default (HTML tags open and close where they shouldn't if they are contained within the data). So, you can just turn escaping off using the escape argument:

library(tableHTML)
tableHTML(mx
          , widths = rep(50, 4)
          , border = 0
          , rownames = TRUE
          , caption = "<b>Table 1: <i>&Phi;<sub>i</sub></i> and their <i>&Sigma;<sub>i</sub></i> and <i>&Tau;<sub>i</sub></i></b>"
          , footer = "<i>Note: </i><i>&Phi;<sub>i</sub></i>. Do re mi fa so la."
          , collapse = "separate"
          , spacing = "5px"
          , escape = FALSE
          , theme = 'scientific'
)

enter image description here