How to customize font size inside the Table of Contents section of a PDF in MATLAB Report Generator?

5 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
To modify the font size inside the "Table of Contents" of a PDF using "MATLAB Report Generator" you need to modify the default "Report" template instead of using the "Table of Contents" report template.
 
Briefly, this can be done with the following steps:
  1. Create a copy of the default reporter template.
  2. Then, modify/customize the copy of the default reporter template.
  3. Finally, tell the report generator to use the customized report template for generating the report.
Please see the below for the above steps in more detail.
Before starting, make sure to use all of the following commands from inside the MATLAB command window with your working directory set to the same location as your MATLAB .M file and all the generated files.
 
1. Create a copy of the default "Report" template by using the static method "mlreportgen.report.Report.createTemplate"
mlreportgen.report.Report.createTemplate("myReportTemplate","pdf");
Here "myReportTemplate" is the name of the file which would be generated with an extension of ".pdftx"
 
1b. Unzip the generated template file:     
unzipTemplate("myReportTemplate.pdftx");
Here "myReportTemplate" is the name of the file which would be generated
 
2. Inside the "stylesheets" folder of "myReportTemplate" file, modify the "root.css" file (obtained after unzipping in previous step), modify the unzipped template by updating the styles for different Table of Content (TOC) levels, like "p.TOC1", "p.TOC2", etc. For example, you may change the font size of the first level of the TOC to 36 with this change in the .CSS file:
p.TOC1 {
font-size: 36pt;
margin-bottom: 2pt;
}
2b. Zip the updated template:
zipTemplate("myReportTemplate.pdftx");
"myReportTemplate.pdftx" would be the new zipped file
3. In the report generation script, use this custom template to create the ‘Report’ object:
rpt = mlreportgen.report.Report("myreport","pdf","myReportTemplate.pdftx");
"myreport" would be the new file name with a file type of .PDF
 
**If you generate a report with a table of contents from this RPT variable, it will have the custom font sizes you set.
You can also refer to this documentation which shows more about customizing the table of contents and generating the report: 
 
**Note: The steps mentioned above can be followed for later MATLAB releases as well. This has been verified until MATLAB R2023b. 

更多回答(0 个)

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by