How to align text in text box?
38 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
TC
am 29 Okt. 2018
Beantwortet: Walter Roberson
am 29 Okt. 2018
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Okt. 2018
Helvetica is a proportional width font. You need a fixed width font.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!