TeX (LaTeX math mode) symbols in legends and labels in MATLAB figures
Show older comments
I am plotting some data which includes estimates of some parameters. I want to describe the estimates by using \hat on the parameter symbols. This I have to do in legends and axis labels fields. I could not fix this matter despite some experiments using information from MATLAB help. Any idea, please to fix this problem. I really appreciate help on this matter which will improve the look of my presentation. Shah
Accepted Answer
More Answers (6)
Mikhail Smirnov
on 10 Feb 2017
You can do like this
plot(1:10);
leg1 = legend('$\bar{x}$','$\tilde{x}$','$\hat{x}$');
set(leg1,'Interpreter','latex');
set(leg1,'FontSize',17);

works well
4 Comments
Walter Roberson
on 1 Sep 2017
Ahmad Alsharif comments to Mikhail Smirnov:
This helped me in creating multi line legend with latex as interpreter
Thomas Gillet
on 17 Dec 2017
Hello Everyone,
When I use Latex interpreter, I am not able to change the font of the legend as you mentionned with set(leg1,'FontSize',17); Have you any idea ? Thank's, Thomas
Mario
on 17 Apr 2023
Unfortunately this doesn't work for me.
I am tried using annotations and legends to write v_{mean on} as v_on to save figure space.
I tried several things:
lgd = legend{'on', 'off', '$$\bar{\itv}$$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\bar{\itv}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\bar{v}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', ['$\bar{v}$','_{on}'], 'v_{mean off}'}
or
lgd = legend{'on', 'off', '$$\overline{\itv}$$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\overline{\itv}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\overline{v}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', ['$\overline{\itv}$','_{on}'], 'v_{mean off}'}
won't work.
It would just add the $$\overline... to the legend text.
I tried both latex and tex interpreter.
I am using MATLAB v 2018b
I figured it out:
lgd = legend('on','off', '$\overline{v}_{on}$', '$\overline{v}_{off}$')
But now my font is not Calibri anymore. it's rather looking like Times New Roman or sth.
set(lgd, 'interpreter', 'latex', 'FontName', 'Calibri')
won't help :(
is there a problem with Calibri + Latex?
Frederik van der Walt
on 4 Apr 2012
Edited: KSSV
on 26 May 2022
l= legend(['$\hat{\psi}$']);
set(l,'Interpreter','Latex');
Shah
on 23 Nov 2011
0 votes
Jordan Brel Ngako Kadji
on 7 May 2020
0 votes
Once I had this problem, I was writing in German and because the german letter 'ä' was not recognised all the latex commands were ignored.
1 Comment
Rostislav Lebedev
on 16 Mar 2022
Try this
title('Verkehrstr\"ager', 'Interpreter', 'latex');
Richard Ulbricht
on 13 Dec 2022
Put this in front of your plotting commands, if you want it for all plots:
set(groot,'defaultLegendInterpreter','latex');
1 Comment
Yan Gao
on 4 Jul 2023
This is the best solution! Thanks, Richard!
Categories
Find more on RF Propagation 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!
