Error with LaTeX formatting in figure legend

5 views (last 30 days)
When using the LaTeX interpreter, the square brackets interfere with the the formatting of the characters within the legend, specifically reverting the subsequent characters after \mu to normal text. In the title, I used $$ to separate the greek letter but this doesn't work with the square brackets. Any help appreciated.
set(0,'defaulttextinterpreter','latex') %set default font to latex
figure
grid on
plot(v,xi1,'-bo',v,chi1,'-.rx',v,psi1,'--kp') % Plot data
legend('\xi [\mum]', '$\xi {[nm]}$','Location','southeast');% Generates legend
xlabel ('Velocity [m/s]', 'fontsize', 12);% Titles x-axis
ylabel ('Metrics [Dimensionless]', 'fontsize', 12);% Titles y-axis
grid on;% Turns grid on
title ('For $\mu$ m-scale Ti', 'fontsize', 14);% Titles plot
Result:
EDIT: I have come across an answer here.
legend('$\xi$ [$\mu$m]', '$\xi$ [nm]','Location','southeast');% Generates legend
set(legend,'Interpreter','latex')
But now I've come across a similar issue... How to set the axes values to LaTeX font?

Accepted Answer

Star Strider
Star Strider on 11 Mar 2018
See if substituting: \left[ for [ and \right] for ] improves your result. It worked when I experimented with it:
legend('$\xi \left[ \mu m \right]$', '$\xi{\left[ nm \right]}$', 'Location','southeast');% Generates legend
  4 Comments
Alexander Muir
Alexander Muir on 11 Mar 2018
Apologies, I meant the tick font. I chose the font that most closely resembled what I wanted:
set(gca, 'FontName', 'Palatino')
Thanks again for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Labels and 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!