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

在Overleaf的gnuplottex中使用LaTeX语法绘图的问题求助

在Overleaf的gnuplottex环境中同时实现LaTeX语法渲染与彩色绘图

问题场景

当指定terminal=pdf时,gnuplottex生成的图片颜色正常,但只能用Gnuplot自身的符号语法(如{/Symbol s})做轴标签;去掉terminal参数改用LaTeX数学公式(如$\sigma$)时,图片丢失颜色,还会出现其他异常。

解决方法

方法1:使用cairolatex终端(推荐)

cairolatex终端同时支持LaTeX渲染文本(包括数学公式)和彩色绘图,是最适配的选择。示例代码:

\begin{gnuplot}[terminal=cairolatex, terminaloptions={font ",10" linewidth 3 color}]
set yrange[0:22]
set xrange[0:60]
set style line 1 dt 1 lw 8 lc rgb 'grey30'
set xlabel "$\\sigma$" enhanced font ",15"
plot "dados.dat" using 1:2 pt 7 ps .5 lw 2 lc rgb "blue"
\end{gnuplot}
  • 核心要点:terminaloptions中必须加入color参数确保颜色生效;LaTeX语法中的反斜杠需用双反斜杠\\转义,避免被Gnuplot提前解析。

方法2:使用带颜色参数的epslatex终端

若偏好epslatex终端,需明确开启颜色支持:

\begin{gnuplot}[terminal=epslatex, terminaloptions={color font ",10" linewidth 3}]
set yrange[0:22]
set xrange[0:60]
set style line 1 dt 1 lw 8 lc rgb 'grey30'
set xlabel "$\\sigma$" enhanced font ",15"
plot "dados.dat" using 1:2 pt 7 ps .5 lw 2 lc rgb "blue"
\end{gnuplot}
  • 说明:epslatex会生成EPS图形文件和对应的LaTeX文本文件,Overleaf会自动完成后续编译,无需手动干预。

通用注意事项

  • 确保enhanced选项处于开启状态(默认开启),该选项是LaTeX语法渲染的前提。
  • 不要使用默认的latex终端,它仅支持黑白绘图,无法满足彩色需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 13:25:30