how to change latex default font in figure?

set(STA1,'A_Label','String','$(i+n)-C_{10}$','Interpreter','latex','FontSize',18,'FontWeight','bold')
When I use latex interpreter ,it can‘t use Times new roman style。how to solve this problem?
(在使用Latex编译器画图时,发现只能使用默认字体,不能更改为新罗马字体,如何解决?)

1 Comment

As far as I know, you can not set/change fonts for any text with Latex as the Text interpreter in MATLAB.
That functionality is not supported in MATLAB yet.

Sign in to comment.

 Accepted Answer

Install and Configure LaTeX:
  • Ensure that you have LaTeX installed on your system, as MATLAB relies on LaTeX for rendering text with the LaTeX interpreter.
Specify the Font in LaTeX:
  • Inside your LaTeX expression in MATLAB, you can specify the font you want to use by adding a LaTeX command like \usepackage{newtxtext}. For Times New Roman, you can use the newtxtext package.
  • Here's an example of how to use Times New Roman in your LaTeX expression:
set(STA1, 'A_Label', 'String', '$\usepackage{newtxtext}$(i+n)-C_{10}$', 'Interpreter', 'latex', 'FontSize', 18, 'FontWeight', 'bold')
Make Sure LaTeX Can Find the Font:
  • Ensure that LaTeX can find the font package you specified. If you've installed LaTeX packages recently, it might require updating LaTeX's font database. You can typically do this by running texhash or mktexlsr in your LaTeX distribution.
Recompile the Plot:
  • After making the changes, recompile your plot, and it should now use the Times New Roman font for the specified text.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

5 Comments

Thanks,I had solved this problem by you enlighten!
but,I modified code,used latex code,
set(STA1,'A_Label','String','$\mathrm{\mathbf{A_{10-14}TEST_{(i+j)}}}$','Interpreter','latex','FontSize',14)
You are welcome.
Hi there, the font is still times new roman in your modified code
set(STA1,'A_Label','String','$\mathrm{\mathbf{A_{10-14}TEST_{(i+j)}}}$','Interpreter','latex','FontSize',14)
Did you figure it out how to use some else font like Arial?
I am wondering whether this method is applicable in Matlab2018Rb?
I found it could not be translated:
"字符串标量或字符向量必须具备有效的解释器语法:
$\usepackage{newtxtext}$H_{z}$"
\usepackage is not a supported latex feature, except possibly for the report generator (and just maybe for certain operations related to uifigures)
xlabel('$\usepackage{newtxtext}$(i+n)-C_{10}$', 'Interpreter', 'latex', 'FontSize', 18, 'FontWeight', 'bold')
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\usepackage{newtxtext}$(i+n)-C_{10}$

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 15 Jan 2024

Commented:

on 13 Jul 2024

Community Treasure Hunt

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

Start Hunting!