Is it possible to rotate a table in a generated report?

6 views (last 30 days)
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!

Accepted Answer

Krishnan Ramkumar
Krishnan Ramkumar on 8 Mar 2019
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')}
  3 Comments
Krishnan Ramkumar
Krishnan Ramkumar on 11 Mar 2019
Hello,
1) You can either change the portrait to landscape layout for entire report or specifc chapters
The below code changes the entire report to landscape
>> rpt.Layout.Landscape = true;
The below code changes the specific chapter to landscape
>> chapter = mlreportgen.report.Chapter();
>> chapter.Layout.Landscape = true;
More information about this can be found at the below documentation link
2) There was a bug with regards to programmatic specification of font size not getting honored and it has been fixed in R2018b_update3. Please find the link below regarding more information about this.
3) With respect to changing the Header style, You can specify something like this. Here I am appending the bold style to the existing Header Style
>> tb.Header.Style = [tb.Style, {mlreportgen.dom.Bold(true)}];

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!