1

我正在尝试使用 Rmarkdown 将条形图添加到表中。我让它为 HTML 工作。

HTML 表格完美运行

a <- c(1,2,3)
b <- c(4,5,6)
table <- as.data.frame(rbind(a,b)) #Demo table for this example
summary_column <- c(40,60) #A summary column, showing 40% and 60%.

#add the summary column using background-color
table[["summary_column"]] <- paste0( 
  "<span style='display: block; border-radius: 4px; padding-right: 4px; background-color: #00457C; color:white; width:",
  summary_column,"%;>", #Size of bar depends on the value of the vector summary_column
  summary_column,"%","</span>") #The bar has an overlaying valuelabel

library(pander)
pandoc.table(table) #convert the table to html table

也可以使用 formattable 包来实现(我的代码与他们的几乎相同)。

结果 HTML 表格

然而,我的问题是
当我编织到 pdf (或 Word )时,如何让这个 barplot 工作?我不想将表格转换为图像,因为我需要表格中的交互性。我认为使用<img>html 标签可能适用于 pdf,但它不起作用(但适用于 HTML):

table[["summary_column"]] <- paste0( #add summary column
  "<img src='bar.bmp'>") #add the bar.bmp to the column

bar.bmp 是一个 5x10px 的 img,我可以放大到 X%。
pdf 不会显示背景颜色或 img。

当我编织到 pdf 时的结果表

我应该为栏添加一个带有 HTML 代码的列,并为栏添加一些 Tex 代码吗?我对乳胶的了解有限。

有没有办法让乳胶引擎(xelatex)读取css或html标签?

谢谢

4

0 回答 0