Clear Filters
Clear Filters

凡例の繰り返しにおける特殊文字(斜体)について

49 views (last 30 days)
irosy
irosy on 11 Feb 2023
Commented: Hiroshi Iwamura on 12 Feb 2023
基本的な質問で失礼いたします.
y=tanh(kx),kは定数で,これを変化させたグラフをを一つの図上にまとめようとしてこのようなコードを書きましたが,凡例のkのみを斜体にしようとしたのにもかかわらず,変数部分までも斜体になってしまいます.
なにかいい手立てはありませんか?
%y=tanh(kx)のグラフ
x = linspace(-5,5,10000);
for i = 1:10
yi = tanh(i*x);
txt = [' \it{k} =',num2str(i)];
plot(x,yi,'DisplayName',txt,'LineWidth',1)
hold on
end
hold off
legend('FontSize',20,'Interpreter','latex')
xlabel('$$x$$','Interpreter','latex','FontSize',20)
ylabel('$$y$$','Interpreter','latex','FontSize',20)

Accepted Answer

Hiroshi Iwamura
Hiroshi Iwamura on 11 Feb 2023
標準フォントに戻すには \rm を使います。
x = linspace(-5,5,10000);
for i = 1:10
yi = tanh(i*x);
txt = [' \it{k} = \rm',num2str(i)]; % <--
plot(x,yi,'DisplayName',txt,'LineWidth',1)
hold on
end
hold off
legend('FontSize',20,'Interpreter','latex')
  3 Comments
Akira Agata
Akira Agata on 12 Feb 2023
+1
ちなみに、\it, \rm などの LaTeX コマンドは LaTeX2e の New Font Scheme Selection (NFSS) 最新版をサポートしていないため、最近の LaTeX では非推奨とされています。今後も長く使用することを想定すると、推奨コマンドを使って以下のように書き換えるのも良いかもしれません。
txt = [' \textit{k} = \textrm{', num2str(i), '}']; % <-- 推奨 LaTeX コマンドで書き換え
Hiroshi Iwamura
Hiroshi Iwamura on 12 Feb 2023
ありがとうございます、勉強になります。
直接関係ないですが、「ここ」とライブエディター(R2022b)で表示が違いますね?
両方とも LaTeX のルールと違うような・・。
% \textit{test}
% \textbf{test}}
% \it \bf test
% \textit{\textbf{test}}
ライブエディター
VS Code(これが正しいと思われる)

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!