MATLAB: How to change the chapter title font in Report Generator

chaptercolorfontMATLAB Report Generatornumbersectionsize;styletitle

I am generating a PDF report programmatically using MATLAB's Report Generator.
I would like to change the chapter title's font, font-size and color. I tried changing it and MATLAB told me that property is not accessible.

Best Answer

To change the full chapter title including the "Chapter X" and the Title:
1. Save a default Chapter template by executing the following line of code:
>> template = mlreportgen.report.Chapter.createTemplate('customChapterStyle.pdftx','pdf')
2. Unzip the PDFTX-file to make edits:
>> unzipTemplate('customChapterStyle.pdftx')
3. In the unzipped "customChapterStyle" folder, open the stylesheet "root.css":
4. Make edits as desired and then save the css file. For example:
h1.SectionTitle1, p.SectionTitle1 {
font-family: 'Times New Roman';
font-size: 40pt;
margin-top: 25pt;
font-weight:bold;
margin-bottom: 10pt;
color: red;
white-space: pre;
-fo-keep-with-next.within-page: always;
}
5. Rezip the PDFTX by executing the following code:
>> zipTemplate('customChapterStyle.pdftx')
6. Go to the script creating the Report and find where the chapter is being created. Set the chapter property of TemplateSrc to the proper file path:
>> ch1 = Chapter
>> ch1.TemplateSrc = 'customChapterStyle.pdftx'
The above changes the style of the full title: Chapter X. Title Text
To remove the component "Chapter X." and just include the Title Text:
>> ch1. Numbered = false;
To include the "Chapter X", but give the Title Text a different font:
1. Make the chapter title a mlreportgen.dom.Text object:
>> ch1title = Text('Change Chapter Title Font');
2. Define the properties of the Text object:
>> fontFamily = FontFamily('Arial');
>> fontSizeObj = FontSize('25px');
>> ch1title.Style = {fontFamily, fontSizeObj};
>> ch1title.Color = 'blue';
Attached is an example that generates a PDF report with the Chapter X. and Title Text reformatted.