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

使用gnuplot cairolatex输出带框标签时文本重复问题求助

解决Gnuplot Cairolatex终端带框标签重复偏移问题

问题重现

使用Cairolatex终端输出带框标签时,文本会出现轻微偏移的重复显示,移除boxed bs 1参数则显示正常。最小复现代码如下:

reset session

set terminal cairolatex pdf color standalone font ',9'
set output "erfx.tex"

set key box bottom spacing 1.4

set zeroaxis
set xrange [-3:3]
set yrange [-1:1]

textstr = '$\displaystyle' \
      . '\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}' \
      . '\int_0^x\, e^{-t^2} \, dt$'

set style textbox 1 opaque fillcolor "white" border linecolor "black" \
    margins 2,2
set label 1 textstr at graph 0.05, 0.9 left \
    boxed bs 1  # 该参数导致文本重复偏移

set xlabel '$x \rightarrow$'
set ylabel '$\textrm{erf}(x) \rightarrow$'

plot erf(x) title 'erf$(x)$'

unset output
unset terminal

执行命令:

gnuplot erfx.plt && pdflatex -interaction=batchmode erfx.tex

解决方案

该问题是Cairolatex终端渲染内置文本框时的bug,推荐两种解决方式:

方法1:用LaTeX原生命令替代Gnuplot文本框

移除Gnuplot的boxed bs 1参数,转而在LaTeX公式外层包裹\boxed{}命令,既保留框效果,又避免重复文本:

reset session

set terminal cairolatex pdf color standalone font ',9'
set output "erfx.tex"

set key box bottom spacing 1.4

set zeroaxis
set xrange [-3:3]
set yrange [-1:1]

# 用LaTeX原生\boxed包裹公式
textstr = '$\displaystyle' \
      . '\boxed{' \
      . '\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}' \
      . '\int_0^x\, e^{-t^2} \, dt' \
      . '}$'

# 无需再设置Gnuplot文本框样式
set label 1 textstr at graph 0.05, 0.9 left

set xlabel '$x \rightarrow$'
set ylabel '$\textrm{erf}(x) \rightarrow$'

plot erf(x) title 'erf$(x)$'

unset output
unset terminal

方法2:切换到Epslatex终端

如果需要保留Gnuplot的文本框样式,可以改用epslatex终端,该终端对文本框渲染更稳定:

# 替换终端设置
set terminal epslatex pdf color standalone font ',9'

编译命令不变,生成的文件可正常用pdflatex编译,无重复文本问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 20:43:30