How to put a hat on letters in a legend?

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!

 채택된 답변

Zoltán Csáti
Zoltán Csáti 2014년 11월 7일

6 개 추천

You should use the LaTeX interpreter:
legend({'$\hat{p}^{CS}$'},'Interpreter','latex')

댓글 수: 3

I used the following command now:
legend({'p','$\hat{p}^{CS}$'})
set(legend,'Interpreter','latex')
Both legend entrees are in a different style now though... how can I change that?
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
Walter Roberson 2020년 9월 20일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

chandan sidhant
chandan sidhant 2020년 9월 20일
편집: Walter Roberson 2020년 9월 20일

3 개 추천

set(legend( '$$|\hat{u}_1|/|\hat{u}_{max}|$$', '$$|\hat{v}_1|/|\hat{u}_{max}|$$'),'Interpreter','Latex','FontSize', 10);

카테고리

태그

질문:

2014년 11월 7일

댓글:

2020년 9월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by