How to align text in text box?
36 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm having trouble formatting text in a text box. I want everything to be aligned to look nice. Below is a snippet of my code.
f_annotate = sprintf(['Compressor HP: %8.0f HP' ...
'\nHeater Power: %9.0f HP' ...
'\nTime difference: %12s' ...
'\nSaved Time: %17s' ...
'\nPercent Error: %8.0f%%'], ...
runningHP, q2, difference, saved_time, percent_error)
dim = [.2 .3 .4 .5];
a = annotation('textbox', dim, 'String', f_annotate, 'FitBoxToText', 'on');%
a.FontSize = 16.2;
a.FontName = 'Helvetica';
a.FontWeight = 'normal';
a.BackgroundColor = 'white';
In the command window, my code outputs:
f_annotate =
Compressor HP: 77 HP
Heater Power: 60 HP
Time difference: 01:02:39
Saved Time: 00:46:59
Percent Error: 15%
This is exactly what I want. However, when I enter it in a text box on a graph, this is what I get:

The alignment is messed up and I'm not sure why. I tried using \t but It's output only works in the command window. The only command that seems to work for me in the text box is \n and using spaces. However, the spaces make the code look a bit messy and they don't line up exactly. Any ideas of how to align the text properly?
0 件のコメント
採用された回答
Walter Roberson
2018 年 10 月 29 日
Helvetica is a proportional width font. You need a fixed width font.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!