how to change latex default font in figure?

69 ビュー (過去 30 日間)
柳燕
柳燕 2024 年 1 月 15 日
コメント済み: Walter Roberson 2024 年 7 月 13 日
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 件のコメント
Dyuman Joshi
Dyuman Joshi 2024 年 1 月 15 日
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.

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

採用された回答

Hassaan
Hassaan 2024 年 1 月 15 日
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 件のコメント
warnerchang
warnerchang 2024 年 7 月 13 日
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 2024 年 7 月 13 日
\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}$

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by