mlreportgen.report.Chapter Class
Namespace: mlreportgen.report
Superclasses: mlreportgen.report.Section
Chapter reporter
Description
Use an object of the mlreportgen.report.Chapter class to add a chapter
to a report.
The mlreportgen.report.Chapter class is a handle class.
Creation
Description
creates a reporter that generates a chapter. The chapter has a new page layout
defined by the default template of the reporter. ch = mlreportgen.report.Chapter
The default template is a portrait page with a header and a footer. The header is empty. If a chapter is the first chapter of the report, the footer contains an automatically generated page number that starts with 1. If the chapter is not the first chapter, the page numbering continues from the last page of the previous chapter. Use the Layout property to override some of the page layout features of the chapter, such as the orientation.
Use the Title property to specify the title.
To add content to the chapter, use the append method of the
mlreportgen.report.Chapter object.
Note
Before you add a chapter to a report, add all of the content to the chapter. Once you add the chapter to a report, you cannot add more content to the chapter.
creates a chapter with the specified title. See the Title property.ch = mlreportgen.report.Chapter(title)
sets properties using name-value arguments. You can specify multiple name-value
arguments in any order.ch = mlreportgen.report.Chapter(PropertyName=Value)
Properties
Chapter title, specified as one of these values:
character vector or string scalar
DOM object
1-by-N or N-by-1 array of string scalars or DOM objects
1-by-N or N-by-1 cell array of string scalars, character vectors, and DOM objects
mlreportgen.report.Titleobject returned by thegetTitleReportermethod
The title appears at the beginning of the chapter and in the header of all chapter pages except the first page. The title also appears in the table of contents of the report.
Inline objects are objects that a paragraph can contain. If the title
value is an inline object, the Chapter object uses a template
from its template library to create a title based on the value. The template
used to create the title depends on whether the title is numbered. A chapter
title is numbered by default. To turn off numbering for this chapter, use
the Numbered property. To turn off numbering for all
other chapters in the report, use the
mlreportgen.report.Section.number method.
If the title is numbered, the title is prefixed in English reports by a
string of the form Chapter N, where N
is the automatically generated chapter number. In some other locales, the
English prefix is translated to the language of the locale. See the
Locale property of
mlreportgen.report.Report for a list of translated
locales.
You can use inline DOM objects to override the character formatting specified by the chapter default title templates.
If the title value is a DOM paragraph or other DOM block object, the chapter inserts the object at the beginning of the chapter. If you use a DOM block object, you can use block elements to customize the spacing, alignment, and other properties of the chapter title. In this case, you must fully specify the title format and provide title numbering yourself.
Note
For the page headers to correctly display the title, the style name of
the title must be SectionTitle1. If the title is
specified as a DOM mlreportgen.dom.Paragraph object with
no StyleName set, the StyleName
property is automatically changed to the correct style name. You can
customize the paragraph style by including DOM style objects in the
Style property of the Paragraph
object. If you use a custom template to format the title, make sure the
style name used by the template is SectionTitle1.
Customize the title style by modifying the
SectionTitle1 style in the custom
template.
Attributes:
GetAccess | public |
SetAccess | public |
Whether to number this chapter, specified as a logical 1
(true) or 0 (false). When you
specify:
[]or1— Number the chapter relative to other chapters in the report. The chapter number appears in the title.0— Do not number the chapter.
The value of the Numbered property
overrides the numbering specified for all report chapters by the
mlreportgen.report.Chapter.number method.
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: logical
Content of the section, specified as one of these values:
character vector or string scalar
DOM objects that can be added to a DOM document part
Reporters, including
Sectionreporters1xN or Nx1 array of string scalars or character vectors
1xN or Nx1 cell array of string scalars, character vectors, and DOM objects
Use the Chapter constructor or append
method to set this property. You cannot set it directly.
Attributes:
GetAccess | public |
SetAccess | public |
Layout of this chapter, specified as an mlreportgen.report.ReporterLayout object. Use the properties of
the ReporterLayout object to override some of the chapter
layout properties that are defined in the template for the chapter.
Example: chapter.Layout.Landscape = true
Attributes:
GetAccess | public |
SetAccess | public |
Source of the template for this reporter, specified in one of these ways:
Character vector or string scalar that specifies the path of the file that contains the template for this reporter
Reporter or report whose template this reporter uses or whose template library contains the template for this reporter
Document Object Model (DOM) document or document part whose template this reporter uses or whose template library contains the template for this reporter
The specified template must be the same type as the report to which you
append this reporter. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template.
If the TemplateSrc property is empty, this reporter uses the
default reporter template for the output type of the report.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Dependent | true |
Name of the template for this reporter, specified as a character vector or string scalar.
The template for this reporter must be in the template library of the template specified by
the TemplateSrc property of this reporter.
Attributes:
GetAccess | public |
SetAccess | public |
Data Types: char | string
Hyperlink target for this reporter, specified as a character vector or string scalar
that specifies the link target ID, or an mlreportgen.dom.LinkTarget object. A character vector or string scalar
value converts to a LinkTarget object. The link target immediately
precedes the content of this reporter in the output report.
Attributes:
GetAccess | public |
SetAccess | public |
Methods
append | Add content to chapter |
add | (Not recommended) Add content to chapter |
getTitleReporter | Get chapter title reporter |
mlreportgen.report.Chapter.number | mlreportgen.report.Chapter.number(report,numbering)
specifies whether to number chapters in a report. If
numbering is true, all
chapters in the report are numbered. |
mlreportgen.report.Chapter.createTemplate |
|
mlreportgen.report.Chapter.customizeReporter | mlreportgen.report.Chapter.customizeReporter(toClasspath)
creates an empty class derived from the
Chapter reporter class with the name
toClasspath. You can use the generated class
as a starting point for creating a custom version of the
Chapter reporter. |
mlreportgen.report.Chapter.getClassFolder |
Get location of folder that contains
Return Values
For more information, see the method for
the |
copy |
Create copy of reporter object and make deep copies of property values
Input Arguments
Return Values
For more information, see the method for
the |
getImpl |
Get implementation of reporter
Note You cannot add content to the reporter after calling this method. Input Arguments
Return Values
For more information, see the method for
the |
Examples
Add a section to a chapter and the chapter to a report. Set the layout orientation of the chapter to landscape.
import mlreportgen.report.* import mlreportgen.dom.* rpt = Report('My Report','pdf'); append(rpt,TitlePage(Title='My Report')); chapter = Chapter('Images'); chapter.Layout.Landscape = true; append(chapter,Section(Title='Boeing 747',Content=Image('b747.jpg'))); append(rpt,chapter); close(rpt); rptview(rpt);
Here is the first page of Chapter 1 in the generated report.

Version History
Introduced in R2017bStarting in R2020b, use the append method instead of the
add method to add content to objects of these Report API classes:
mlreportgen.report.Reportmlreportgen.report.Chaptermlreportgen.report.Sectionslreportgen.report.Report
To add content to a DOM API object, such as an
mlreportgen.dom.Paragraph object, continue to use the
append method of the DOM object. The advantage of using
append to add content to Report API objects is that you use
the same method name as you use to add content to DOM API objects.
There are no plans to remove the add methods of the
Report, Chapter, or Section
classes. Report API programs that use the add methods will continue
to run.
To update existing code, replace the method name add with
append as shown by the examples in the table.
| Not Recommended | Recommended |
|---|---|
import mlreportgen.report.* import mlreportgen.dom.* rpt = Report("My Report","pdf"); ch = Chapter("My Chapter"); sect = Section("My Section"); para = Paragraph("My Content "); append(para,"more Content"); add(sect,para); add(ch,sect); add(rpt,ch); close(rpt); rptview(rpt); |
import mlreportgen.report.* import mlreportgen.dom.* rpt = Report("My Report","pdf"); ch = Chapter("My Chapter"); sect = Section("My Section"); para = Paragraph("My Content "); append(para,"more Content"); append(sect,para); append(ch,sect); append(rpt,ch); close(rpt); rptview(rpt); |
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)