Matlab图例使用Latex解释器时文字溢出

8
我正在尝试在使用Latex解释器时为matlab图中添加图例,但是当我将图例设置为使用Latex解释器时,其中的文本会溢出到图例框之外。我已经尝试调整文本大小,但无论字体大小如何,都会发生这种情况。以下是我的脚本的相关部分:
I = legend([h1 h2 h3],'RainFall Flux', ... 
           'Temperature term ($$\rho \alpha$$dT)', ...
           'Salinity term ($$\rho \beta$$dS)');
c=get(I,'children');
set(c(5),'LineWidth',3); %adjust lineWidth in legend
set(c(2),'LineWidth',3); %adjust lineWidth in legend
set(I,'interpreter','latex'); %set Latex interpreter
set(I,'FontSize',15);

我猜这是因为Matlab在使用Latex解释文本后没有考虑到正确的字符大小。然而,我不知道如何解决这个问题。
任何见解都将不胜感激!谢谢!
3个回答

1

我对你的代码没有任何问题,在R2007b中,如果我从你的第一个语句中删除[h1 h2 h3](和逗号),那么就没有问题了。然而,在调用latex解释器或设置FontSize后,图例中的线宽度变化会消失,因此我不得不改变这些顺序。换句话说,这段代码可以工作:

x=[1:100]; y=sin(pi*x/50); plot(x,y,x,y.^2,x,sqrt(abs(y)));
I = legend('RainFall Flux', ... 
           'Temperature term ($$\rho \alpha$$dT)', ...
           'Salinity term ($$\rho \beta$$dS)');
c=get(I,'children');
set(I,'interpreter','latex'); %set Latex interpreter
set(I,'FontSize',15);
set(c(5),'LineWidth',3); %adjust lineWidth in legend
set(c(2),'LineWidth',3); %adjust lineWidth in legend

0

另一种方法是在设置默认解释器为LaTex之前更改字体大小。我过去曾经这样做过,并注意到上面的答案也在这样做。


0

我从未找到过这个问题的完美解决方案(即 MATLAB 自动为 LaTeX 获取正确的框)。

但是以下是一种不错的权宜之计:通过添加~字符来强制额外空间 --- LaTeX 解释器会隐藏它们,但它们会被包含在宽度计算中。

~添加到图例的最长行中,以扩展框的宽度。

I = legend([h1 h2 h3],'RainFall Flux', ... 
       'Temperature term ($$\rho \alpha$$dT)~~~', ...
       'Salinity term ($$\rho \beta$$dS)');

试着玩弄它,看看需要添加多少个波浪线才能强制适合。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接