Text inside legend box does not fit in automatically
20 views (last 30 days)
Show older comments
I recently updated my MATLAB to 2025b and am experiencing some trouble when drawing figures.
As noted by the attached figure, the text inside the legend does not fit into the box automatically.

I tried manually adjusting the box size using commands like
lgd.Units = 'normalized';
pos = lgd.Position;
pos(1) = pos(1) + 0.003;
pos(2) = pos(2) - 0.035;
pos(3) = pos(3) * 1.001;
pos(4) = pos(4) * 1;
lgd.Position = pos;
But manually adjusting is highly laborious since I have to try several times to find the exact box size that covers the text.
It seems it happens when I use 'interpreter',' latex' option, and saving the file using .pdf extension. It didn't happen when I used the 2024b version of MATLAB.
If possible could anyone tell me how to draw figures with appropriate box size without manually adjusting it as I could in the previous version of MATLAB.
I have to use both 'interpreter', 'latex' option, and saving the file using the .pdf extension.
0 Comments
Answers (1)
dpb
on 26 Nov 2025
Edited: dpb
on 26 Nov 2025
I expect this is another manifestation of the changes with the new rendering engine introduced with R2025.
Submit this to Mathworks as an official support request/bug at <Product Support Page>. I would suggest supplying a comparison figure with prior release to illustrate the issue.
I'm not sure otomh about a programmatic way using the 'Extent' to make a fixup will work(*); perhaps Mathworks can provide that as part of their response. Meanwhile, unless there is some other unavoidable feature in R2025 that you need, I'd suggest to stick with the prior release if it works as desired until do get a better resolution from Mathworks support.
(*) Well, let's see if can create the symptom...guessing it also has to do with the subplot configuration making for smaller axes than full-sized...
TL=tiledlayout(2,3);
for i=1:4, hT(i)=nexttile(TL); end % work our way down
yMax=0.0015;
y0=[linspace(0.0003,0.001,3) yMax];
xMax=1.04;
x=linspace(0,xMax).';
d=abs(log(y0/xMax));
y=y0.*exp(-d.*x);
plot(x,y)
hT(i).YAxis.Exponent=0;
hT(i).YAxis.TickLabelFormat='%0.4f';
hLg=legend('RANK','Cyclical long','Cyclical + LR Income','Ineq + Risk', ...
'Interpreter','latex');
Well this doesn't reproduce OP's issue; the text fits in the legend but the legend is way bigger than the axes -- not sure just how got that many on a figure with the aspect ratio his figure shows.
Need to add the code that generated the figure...
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!