我正在尝试使用带有 cairolatex 的 gnuplot 作为输出以及盒装标签。没有标签周围的框,输出就可以了。但是,一旦我在标签周围放上框,文本就会出现两次,彼此略有偏移。 MWE如下:
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
# Without "boxed bs 1" it works fine, but without the surrounding box
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
结果如下:
任何帮助将不胜感激。
确实是一个非常奇怪的行为。 这不是一个真正的解决方案,但我的观察:(也许其他人可以得出正确的结论)。
如果我(新)启动 gnuplot 控制台,加载您的脚本并从操作系统控制台(在我的情况下为 Windows)运行
pdflatex
,我可以重现您的结果。
但是,如果我从同一个打开的 gnuplot 控制台第二次加载您的脚本并运行
pdflatex
,我在最终的 PDF 中再也看不到这个双文本框了。
所以,cairolatex 终端和/或文本框的一些初始 gnuplot 设置可能一定有问题。
.tex
代码中,您的标签出现两次。我不确定,如果这应该是那样的话。...
\settowidth{\gptboxwidth}{\widthof{$\displaystyle\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x\, e^{-t^2} \, dt$}}
\advance\gptboxwidth by 4\fboxsep
\savebox{\gptboxtext}{\parbox[c][\totalheight+4\fboxsep]{\gptboxwidth}{\centering{$\displaystyle\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x\, e^{-t^2} \, dt$}}}
\definecolor{tbcol}{rgb}{1.00,1.00,1.00}
\put(1064,3777){\makebox(0,0)[l]{\colorbox{tbcol}{\usebox{\gptboxtext}}}}
\csname LTb\endcsname%%
\settowidth{\gptboxwidth}{\widthof{$\displaystyle\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x\, e^{-t^2} \, dt$}}
\advance\gptboxwidth by 4\fboxsep
\savebox{\gptboxtext}{\parbox[c][\totalheight+4\fboxsep]{\gptboxwidth}{\centering{$\displaystyle\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x\, e^{-t^2} \, dt$}}}
\settowidth{\gptboxwidth}{\usebox{\gptboxtext}}
\advance\gptboxwidth by 2\fboxsep
\put(1064,3777){\makebox(0,0)[l]{\framebox[\gptboxwidth]{\usebox{\gptboxtext}}}}
...
所以,一个不太令人满意的解决方案是 add 在脚本末尾添加以下几行:
set output "erfx.tex"
replot
set output
system('pdflatex erfx.tex')
有了这个,从 gnuplot 控制台加载脚本,我一直得到一个文本框。
问题出在这条命令上
set style textbox 1 opaque
Gnuplot 通过绘制一次内容来实现“不透明框”属性,使用它来确定覆盖的确切区域,绘制一个填充确定区域的实心矩形,然后最后再次写入文本,以便它显示在顶部固体填充矩形。
不幸的是,该序列不适用于 {eps/ps/pdf}latex 终端,因为它们将所有文本输出收集到一个单独的层中,供 LaTeX 渲染。因此,前后矩形文本都被发送到 LaTeX。
如果将其切换为
,您的标签应该会按预期工作set style textbox 1 transparent
程序可能在这方面更聪明,但这就是这里发生的事情。