4,175 views (last 30 days)

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

Matthew Simoneau
on 30 May 2014

Edited: MathWorks Support Team
on 28 Apr 2021

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.

For more information on using LaTeX in plot titles, labels, and legends, refer to the following example:https://www.mathworks.com/help/matlab/creating_plots/greek-letters-and-special-characters-in-graph-text.html#mw_421aadf2-3104-41f5-ae7e-57bf5f7cdde3

SOURAV KUMAR
on 29 Mar 2021

You should use the following syntax for legend() :

legend({'$\Pi_{5}=60$','$\Pi_{5}=30$','$\Pi_{5}=20$','$\Pi_{5}=50$','$\Pi_{5}=70$'},'Interpreter','latex','Location','southeast');

It works on my system (Matlab R2013a),

check on yours

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

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

Frederik van der Walt
on 4 Apr 2012

l= legend(['$\hat{\psi}$']);

set(l,'Interpreter','Latex');

Steven
on 22 Nov 2011

Try with Latex interpreter, something like

title(['$ latex $'],'interpreter','latex')

Jordan Brel Ngako Kadji
on 7 May 2020

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

Start Hunting!