MATLAB: Is there additional white space at the bottom of table cells when creating a Word document using MATLAB Report Generator R2019b

MATLAB Report Generator

I am creating a Word document using MATLAB Report Generator:
%%Import Report Generator Classes
import mlreportgen.dom.*
%%Create a new document
d = Document('example','docx');
%%Add a table
% Define a full width table style with borders
tableStyle = {Border('solid'), RowSep('solid'), ColSep('solid'),...
Width('100%')};
% Create a style to center the text in all cells
cellStyle = {HAlign('center'), VAlign('middle')};
% Create a table with two rows and two columns
t = Table( {'Hello', 'World'; 'Hello', 'Universe'} );
% Apply the styles
t.Style = tableStyle;
t.TableEntriesStyle = cellStyle;
% Add the table to the document
append(d,t);
%%Close the document
close(d);
This produces a table which looks like:
Where there is this additional spacing/margin at the bottom of each cell. What I would like to have however is the following:
Similar what a table looks like when you insert one in Word interactively. I have tried all kinds of things to get rid of this additional space I tried setting InnerMargin and OuterMargin of the tableStyle as well as the cellStyle but nothing appears to help.

Best Answer

The main "problem" here is that when you create a Table without explicitly applying a Template Style, i.e. you do not use:
t = Table(data, 'SomeStyleName')
or:
t = Table;
t.StyleName = 'SomeStyleName';
then there really are no styles applied to the table or its contents. Meaning that inside the cells you are creating Paragraphs with the 'Normal' style and the 'Normal' style in Word by default has a "Space After" of 10pt; that is the white space which you see here. This is different from when you interactively insert a table in Word, when you do that, Word silently explicitly applies a style to the table; by default the 'Table Grid' style, which explicitly sets "Space After" to 0.
So what you will want to do here to get a "default Word style" table without additional spacing in the cells is apply that 'Table Grid' style:
t.StyleName = 'Table Grid';
Or create a Word Template in which you define a new Table Style (without spacing) which you apply to your table: