Remove whitespace in Legend with Latex Labels
Show older comments
Hi, does anyone know why there is so much whitespace after each entry in the legend here? I've tried to shrink the legend width by doing:
pos = legend.Position;
pos(3) = 0.5*pos(3);
legend.Position = pos;
But this hasn't worked. I've attached the code below.
Any help would be appreciated.

Here is the code below: (I'm sure there is a better way to write the legend names out, but I'm lazy and this was good enough for my purposes).
f = figure;
hold on
plot(Cl, Cm(:,1),"-bsquare")
plot(Cl, Cm(:,3),"-bdiamond")
plot(Cl, Cm(:,5),"-b^")
plot(Cl, Cm(:,7),"-bv")
plot(Cl, Cm(:,2),"-rsquare")
plot(Cl, Cm(:,4),"-rdiamond")
plot(Cl, Cm(:,6),"-r^")
plot(Cl, Cm(:,8),"-rv")
hold off
xlim([-1.1, 1.4])
leg = legend({'$x_{cg}=0.18\bar{c}, \delta_e = 0\degree $','$x_{cg}=0.22\bar{c}, \delta_e = 0\degree $','$x_{cg}=0.26\bar{c}, \delta_e = 0\degree $','$x_{cg}=0.30\bar{c}, \delta_e = 0\degree $','$x_{cg}=0.18\bar{c}, \delta_e = 5\degree $','$x_{cg}=0.22\bar{c}, \delta_e = 5\degree $','$x_{cg}=0.26\bar{c}, \delta_e = 5\degree $','$x_{cg}=0.30\bar{c}, \delta_e = 5\degree $'},'Interpreter','latex', 'Location','northeast', 'FontSize',11);
% pos = leg.Position;
% pos(3) = 0.25*pos(3); % Tried this, didn't work
% leg.Position = pos;
grid on
ax = gca;
ax.GridLineWidth = 1.5;
ax.XAxis.MinorTick = 'on';
ax.XMinorGrid = 'on';
ax.YAxis.MinorTick = 'on';
ax.YMinorGrid = 'on';
f.Units = 'pixels';
f.Position = [10,10,990,490];
2 Comments
Walter Roberson
on 23 Sep 2025
For testing, could you attach a .mat that defines Cl and Cm ?
Accepted Answer
More Answers (0)
Categories
Find more on Legend 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!
