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

标签 r html-table formatting tablehtml

HTML 在行名、标题和页脚中运行良好。与 colnames 的直觉相反,它不起作用。如何在 colname 中实现等效格式?

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

最佳答案

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

关于r - 如何格式化 tableHTML 包中的 colnames 文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47471476/

相关文章:

java - 如何格式化从文件打印的数据?

r - 如何在 Rmarkdown 中的表格中添加精美的图标?

r - 在 R 中定义场合(按季节)而不基于年份

r - 将 RCurl 与嵌入 null 的 ftp 服务器结合使用

javascript - Visual Studio.NET 2010 javascript 格式化

Python MIME 文本格式

r - 仅绘制特定轴文本标签

jquery - 获取表格单元格内的文本高度

css - 在 IE 6 和 7 中使用列表和表格进行绝对定位/Z-Index 时遇到问题

php - 在表格单元格内放置一个提交按钮