Making a table with different column widths and autofit contents

I am trying to make a table with three different column widths and I just can't seem to get it right.
When I use ColWidth in any of the following formats:
Alltb(1,1)=ColWidth('1in');
Alltb.ColWidth='1in';
Alltb.entry(1,1).Style = {ColWidth('1in')};
Alltb.Children.entry(1,1).Style = {ColWidth('1in')};
Alltb.Children.Entries(1,1).Style = {ColWidth('1in')};
I get an error that that doesn't exist, some variation of:
Unrecognized property 'ColWidth' for class 'mlreportgen.dom.TableEntry'.
I don't understand what mistake I'm making. Alltb is defined as a "Table()". I have tried defining a table entry and then applying colwidth to that with the same problem. I am using Matlab2017b.

1 Comment

I found ColSpecGroups which may be the correct one to use for a document whereas colwidth is used for a ppt, but I can't find a single example of how to use it. I've been looking for hours. I'm so frustrated just trying to format this stupid table.
Alltb.ColSpecGroups(1) = Width('.75in');
returns:
The following error occurred converting from mlreportgen.dom.Width to double:
Conversion to double from mlreportgen.dom.Width is not possible.
When I make the table with Alltb=Table(3) There is a ColSpecGroups argument. I just can't find any examples of how to enter in the information.
Alltb.ColSpecGroups(1) = TableColSpecGroup('0.75in');
and
Alltb.ColSpecGroups(1) = TableColSpec('0.75in');
return the same error:
No constructor 'mlreportgen.dom.TableColSpecGroup' with matching signature found.
This line:
Alltb.ColSpecGroups(1) = '0.75in';
returns:
Subscripted assignment dimension mismatch.
This liine:
Alltb.ColSpecGroups{1} = '0.75in';
returns:
Invalid Table column spec group.
Which is weird, because
Alltb.ColSpecGroups
ans =
[]

Sign in to comment.

 Accepted Answer

I found the answer. It's stupid and unintuitive. Here is the code that worked:
grps(1)=TableColSpecGroup;
grps(1).Span=1;
grps(1).Style={Width('1in')};
grps(2)=TableColSpecGroup;
grps(2).Span=2;
grps(2).Style={Width('2.75')};
Alltb.ColSpecGroups = grps;
Where Span sets the number of columns that the spec applies to.

More Answers (0)

Asked:

on 8 Mar 2018

Answered:

on 9 Mar 2018

Community Treasure Hunt

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

Start Hunting!