フィルターのクリア

How to align of words in matlab legend ?

32 ビュー (過去 30 日間)
MD MOSTAKIM ALAM SOHAG
MD MOSTAKIM ALAM SOHAG 2022 年 1 月 24 日
編集済み: Niklas Kurz 2022 年 6 月 23 日
plase share a code for align the words in matlab legend.
  1 件のコメント
Mathieu NOE
Mathieu NOE 2022 年 1 月 24 日
hello
I assume you know the string length of the words you use in the legend
Decane is one letter shorter compared to Heptane, so simply add one trailling blank to it and you should be good

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

回答 (1 件)

DGM
DGM 2022 年 1 月 24 日
編集済み: DGM 2022 年 1 月 24 日
So long as a variable-width font is in use, you're going to be fighting it.
y = rand(3,10);
plot(y);
% all three strings have the same number of characters
lstr = {'Heptane 100\circC', ... % note that they all line up here
'Decane 100\circC', ...
'Thing 100\circC'};
legend(lstr)
Tabs don't seem to work either. I can think of two options
  • Use a fixed-width font and add regular spaces as padding
  • Compensate for variable-width fonts by using various space widths
To the latter option, see this:
y = rand(3,10);
plot(y);
lstr = {'Heptane 100\circC', ... % this is the reference line
['Decane' repmat(char(8202),1,10) '100\circC'], ...
['Thing' repmat(char(8202),1,26) '100\circC']};
legend(lstr)
It will vary depending on the font used, and it won't likely be perfect.
  1 件のコメント
Niklas Kurz
Niklas Kurz 2022 年 6 月 23 日
編集済み: Niklas Kurz 2022 年 6 月 23 日
It is ludicrous a fully commercial high level program like Matlab offers no proper aligning in legends. Can't it be added with a next patch? For example enable latex standalone documents in legends.

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

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by