MATLAB Answers

TeX (LaTeX math mode) symbols in legends and labels in MATLAB figures

5,134 ビュー (過去 30 日間)
Shah
Shah 2011 年 11 月 22 日
回答済み: Jordan Brel Ngako Kadji 2020 年 5 月 7 日
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

  0 件のコメント

サインインしてコメントする。

採用された回答

Matthew Simoneau
Matthew Simoneau 2014 年 5 月 30 日
編集済み: MathWorks Support Team 2018 年 11 月 8 日
By default, MATLAB supports a subset of TeX markup. For a list of supported symbols, see the documentation .
For more symbols, you can use LaTeX markup by setting the Interpreter property to 'latex'. Use dollar symbols around the text. For example:
title('$\hat{\psi}$','Interpreter','latex')
If you are using the legend function in R2018a or earlier, you must specify the labels as a cell array to distinguish the labels from the name-value pairs. In R2018b and later, the cell array is not needed.
plot(1:10)
legend({'$\hat{\psi}$'},'Interpreter','latex') % R2018a and earlier
legend('$\hat{\psi}$','Interpreter','latex') % R2018b and later
When you use LaTeX markup, the displayed text uses the default LaTeX font style. The FontName, FontWeight, and FontAngle properties no longer have an effect. To change the font style, use LaTeX markup instead.

  0 件のコメント

サインインしてコメントする。

その他の回答 (5 件)

Mikhail Smirnov
Mikhail Smirnov 2017 年 2 月 10 日
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

  2 件のコメント

Walter Roberson
Walter Roberson 2017 年 9 月 1 日
Ahmad Alsharif comments to Mikhail Smirnov:
This helped me in creating multi line legend with latex as interpreter
Thomas Gillet
Thomas Gillet 2017 年 12 月 17 日
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

サインインしてコメントする。


Frederik van der Walt
Frederik van der Walt 2012 年 4 月 4 日
l= legend(['$\hat{\psi}$']);
set(l,'Interpreter','Latex');

  0 件のコメント

サインインしてコメントする。


Steven
Steven 2011 年 11 月 22 日
Try with Latex interpreter, something like
title(['$ latex $'],'interpreter','latex')

  1 件のコメント

Shah
Shah 2011 年 11 月 22 日
Thanks Steven but its not working here. I am using MATLAB 7.9.0.
I wrote legend(['$\hat{\psi}$'],'interpreter','latex') but got a warning: Unable to interpret TeX string '$\hat{\psi}$'interpreterlatex'. Same appear in the legend field.

サインインしてコメントする。


Shah
Shah 2011 年 11 月 23 日
......... Its done! Actually, the default interpreter in MATLAB for legend is 'tex', I guess. It is not changed from the code line. What I had to do was to right click on the legend in the figure window and then changed the 'interpreter' from 'tex' to 'latex'. This action changed the latex statement in the legend field to Math mode.
Cheers Shah

  0 件のコメント

サインインしてコメントする。


Jordan Brel Ngako Kadji
Jordan Brel Ngako Kadji 2020 年 5 月 7 日
Once I had this problem, I was writing in German and because the german letter 'ä' was not recognised all the latex commands were ignored.

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by