MATLAB: Is it possible to rotate a table in a generated report

fontfontsizeformattingMATLAB Report Generatorreportreport generatortable

Hi all, is it possible to rotate a table that I have added to a report using Report Generator?
Simplified code so far is:
rpt = Report('Title','pdf');
tb = FormalTable(table_with_many_columns_and_some_rows);
add(rpt, tb);
My problem is that the table
table_with_many_columns_and_some_rows
has about 9 rows and 24 columns, so it does not fit the standard A4 size when generating the PDF report. Therefore, is it possible to rotate the table in the PDF so that it is read in landscape instead of portrait?
Alternatively, how could I format the font size of the table contents to shrink the table so that the whole wide table fits within the A4 page?
Thanks!

Best Answer

Hi,
There are multiple ways to fit a large table in a A4 size paper.
1) You can set the report layout to be landscape and then add the FormalTable to the report
For example:
rpt = Report('Title','pdf');
rpt.Layout.Landscape = true;
tb = FormalTable();
tb.RowSep = 'Solid';
tb.ColSep = 'Solid';
tb.Border = 'Solid';
add(rpt, tb);
2) Starting from R2018b we inroduced a new utility called as TableSlicer, which slices the input table into multiple chunks and add each chunk to the report. You can specify max number of columns in each chunk and also specify the number of columns to retain in each slice.
rpt = mlreportgen.report.Report('title', 'pdf');
tb = mlreportgen.dom.FormalTable(magic(25));
tb.RowSep = 'Solid';
tb.ColSep = 'Solid';
tb.Border = 'Solid';
slicer = mlreportgen.utils.TableSlicer("Table", tb, "MaxCols",...
6, "RepeatCols", 1);
slices = slicer.slice();
for slice = slices
% Adding title to each slice. Here am adding the Repeated column, start column and end column
str = sprintf("Repeated Column Index: %d ,SlicedColumns: From column %d to column %d",...
slicer.RepeatCols,slice.StartCol, slice.EndCol);
para = mlreportgen.dom.Paragraph(str);
para.Bold = true;
para.Style = [para.Style,{mlreportgen.dom.KeepWithNext(true),...
mlreportgen.dom.OuterMargin("0pt","0pt","5pt","0pt")}];
add(rpt, para);
add(rpt, slice.Table);
end
close(rpt);
More information about this can be found in the below documentation link
Regarding reducing the font size of the table entries in a FormalTable, you can specify font size in table entries style property of the formal table
tb.TableEntriesStyle = {mlreportgen.dom.FontSize('20pt')}