Helvetica is a proportional width font. You need a fixed width font.
How to align text in text box?
38 次查看(过去 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 个评论
采纳的回答
更多回答(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!