如何格式化tableHTML包中的colnames文本?

时间:2017-11-24 10:40:16

标签: r html-table formatting tablehtml

HTML在rownames以及标题和页脚中工作正常。与姓氏中的直觉相反,它不起作用。我怎样才能在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 个答案:

答案 0 :(得分:2)

tableHTML默认会转义><(如果HTML数据包含在数据中,则不会打开和关闭HTML标签)。因此,您可以使用escape参数转义转义:

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