How do you align numbers within a column in UItable?
Show older comments
We're using GUIDE to build financial applications for investment bankers. They expect to see a column of dollar figures right aligned but there seems to be no obvious way to right align characters in a column in UItable. Any help would be GREATLY appreciated!!!
Accepted Answer
More Answers (2)
Oleg Komarov
on 10 Mar 2011
I came up with this solution:
dat = {'23234.43 $'; '234.43 $'; '0.23 $'};
Pad string amounts with blanks
l = cellfun(@length,dat);
dat = num2cell([arrayfun(@blanks,max(l)-l,'un',0) dat],1);
dat = strcat(dat{:});
Create table with courier font
f = figure('Position',[200 200 400 150]);
cnames = 'Amounts';
rnames = {'First','Second','Third'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 360 100],...
'fontname','courier');
Oleg
2 Comments
Peter
on 10 Mar 2011
Oleg Komarov
on 10 Mar 2011
You had to change fontname to a monospaced set
Walter Roberson
on 10 Mar 2011
0 votes
Does setting the ColumnFormat to 'bank' work ?
2 Comments
Oleg Komarov
on 10 Mar 2011
It will work with numeric datatypes...not with strings.
Peter
on 10 Mar 2011
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!