how to change latex default font in figure?

67 Ansichten (letzte 30 Tage)
柳燕
柳燕 am 15 Jan. 2024
Kommentiert: Walter Roberson am 13 Jul. 2024
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 Kommentar
Dyuman Joshi
Dyuman Joshi am 15 Jan. 2024
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Hassaan
Hassaan am 15 Jan. 2024
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 Kommentare
warnerchang
warnerchang am 13 Jul. 2024
I am wondering whether this method is applicable in Matlab2018Rb?
I found it could not be translated:
"字符串标量或字符向量必须具备有效的解释器语法:
$\usepackage{newtxtext}$H_{z}$"
Walter Roberson
Walter Roberson am 13 Jul. 2024
\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}$

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by