You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用richtext_grob绘制粗体字体?

问题:richtext_grob无法渲染粗体字体

我尝试了多种方式使用richtext_grob绘制粗体字体,但均未成功。以下是我的代码:

library(gridtext)
library(grid)

text1 <- "Some text NOT in bold"
text2 <- "Some text **in bold**"
text3 <- c(paste0("<p style='font-weight:bold;'>\n",
                  "Some text in bold",
                  "</p>\n"))
text4 <- "<span style='font-weight:bold;'>Some text in bold</span>"

g <- richtext_grob(text = c(text1, text2, text3, text4), 
                   x = c(0.5, 0.5, 0.5, 0.5), 
                   y = c(0.9, 0.8, 0.7, 0.6))

grid.newpage()

grid.draw(g)

输出结果中所有文本均未显示粗体效果,该输出通过Plots窗口的“Export -> Save as Image...”生成。

我的sessionInfo()结果如下:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8    LC_MONETARY=German_Germany.utf8
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.utf8    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gridtext_0.1.4

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10     digest_0.6.29   magrittr_2.0.3  evaluate_0.15   stringi_1.7.6   rlang_1.0.6    
 [7] cli_3.6.0       rstudioapi_0.13 xml2_1.3.3      rmarkdown_2.14  tools_4.2.2     stringr_1.4.0  
[13] markdown_1.1    xfun_0.31       yaml_2.3.5      fastmap_1.1.0   compiler_4.2.2  htmltools_0.5.5
[19] knitr_1.39 

我的目标是制作PDF标题页,需要设置不同颜色、字号、字体类型、文本对齐方式等,希望能使用HTML标签实现。

内容的提问来源于stack exchange,提问作者Tobi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 10:24:59