How to put a hat on letters in a legend?
119 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MC3105
am 7 Nov. 2014
Kommentiert: Walter Roberson
am 20 Sep. 2020
Hey everyone,
I am trying to create a legend for one of my graphs that contains two entries: p and p^^CS - I want a hat on the p and I also want CS in the index....
Can someone tell me how to do that??
Thanks a lot!
0 Kommentare
Akzeptierte Antwort
Zoltán Csáti
am 7 Nov. 2014
You should use the LaTeX interpreter:
legend({'$\hat{p}^{CS}$'},'Interpreter','latex')
3 Kommentare
Zoltán Csáti
am 7 Nov. 2014
By example:
p = plot(1,2,'O');
hold on
pCS = plot(1,3,'rO');
leg = legend({'p';'$\hat{p}^{CS}$'});
set(leg,'Interpreter','latex');
Now you get the same format. However it seems that the hat changed its style. It is definitely because of it, since after
plot('1,2,'o');
legend({'p'},'Interpreter', 'latex');
results the same style for p.
Walter Roberson
am 20 Sep. 2020
It turns out to be generally difficult in LaTeX to create upright symbols or modified alphabets (such as hat modifier). The easy methods that remove the italics in math mode, do not apply to symbols.
The LaTeX solution to this involves using the amsmath package (in particular amstext). Unfortunately, MATLAB does not currently provide any method for importing the amsmath package.
Weitere Antworten (1)
chandan sidhant
am 20 Sep. 2020
Bearbeitet: Walter Roberson
am 20 Sep. 2020
set(legend( '$$|\hat{u}_1|/|\hat{u}_{max}|$$', '$$|\hat{v}_1|/|\hat{u}_{max}|$$'),'Interpreter','Latex','FontSize', 10);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/363295/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!