MathJaxr中温度单位(℃/℉/K)符号与单位紧邻显示问题
解决度数符号与温度单位紧邻显示的问题
针对你在Shiny应用中使用mathjaxr时遇到的度数符号与温度单位(F/C/K)无法紧邻的问题,提供以下几种可行方案:
方案1:使用\!强制消除空格(针对\circ)
MathJax在数学模式下会自动给符号和字母之间添加空格,你可以用\!(负空格命令)抵消默认空格,让度数符号和单位紧贴:
library(shiny) library(mathjaxr) ui <- fluidPage( title = 'MathJax Examples', uiOutput('ex3') ) server <- function(input, output, session){ output$ex3 <- renderUI({ withMathJax( helpText( "$$3^{\circ}\!F$$" # 用\!消除默认空格 ) ) }) } shinyApp(ui = ui, server = server)
方案2:使用\degree命令并加载对应MathJax扩展
\degree是MathJax中专门的度数符号命令,但默认未加载支持它的gensymb扩展,需要手动配置加载:
library(shiny) library(mathjaxr) ui <- fluidPage( title = 'MathJax Examples', # 配置MathJax加载gensymb扩展以支持\degree tags$head( tags$script(type = "text/x-mathjax-config", 'MathJax.Hub.Config({ TeX: { extensions: ["gensymb.js"] } });' ) ), uiOutput('ex3') ) server <- function(input, output, session){ output$ex3 <- renderUI({ withMathJax( helpText( "$$3\degree F$$" # 直接使用\degree,自动与单位紧贴 ) ) }) } shinyApp(ui = ui, server = server)
方案3:将度数符号与单位合并为一个数学元素
把度数符号和单位放在同一{}块中,让MathJax将它们视为整体,避免自动添加空格:
library(shiny) library(mathjaxr) ui <- fluidPage( title = 'MathJax Examples', uiOutput('ex3') ) server <- function(input, output, session){ output$ex3 <- renderUI({ withMathJax( helpText( "$$3{^\circ F}$$" # 把度数符号和F放在同一组内 ) ) }) } shinyApp(ui = ui, server = server)
内容的提问来源于stack exchange,提问作者user8229029
相关产品推荐
相关产品推荐

