Use an object of the
mlreportgen.report.Chapter class to add a chapter
to a report.
mlreportgen.report.Chapter class is a
For information on class attributes, see Class Attributes.
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
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(
sets properties using name-value pairs. You can specify multiple name-value pair
arguments in any order. Enclose each property name in single quotes or double
ch = mlreportgen.report.Chapter(
Title— Chapter title
Chapter title, specified as one of these values:
String scalar or character vector
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/or DOM objects
SectionTitle reporter returned by the
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
Numbered property. To turn off numbering for all
other chapters in the report, use the
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
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.
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
StyleName set, the
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
object. If you use a custom template to format the title, make sure the
style name used by the template is
Customize the title style by modifying the
SectionTitle1 style in the custom
Numbered— Whether to number this chapter
Whether to number this chapter, specified as
false. If the value of
is empty or
true, the chapter is numbered relative to
other chapters in the report. The chapter number appears in the title. If
the value of
chapter is not numbered. The value of the
property overrides the numbering specified for all report chapters by the
Content— Content of this section
Content of the section, specified as one of these values:
String scalar or character vector
DOM objects that can be added to a DOM document part
1xN or Nx1 array of string scalars or character vectors
1xN or Nx1 cell array of string scalars, character vectors, and/or DOM objects
Chapter constructor or
method to set this property. You cannot set it directly.
Layout— Layout of this chapter
Layout of this chapter, specified as an
mlreportgen.report.ReporterLayout object. Use the properties of
ReporterLayout object to override some of the chapter
layout properties that are defined in the template for the chapter.
chapter.Layout.Landscape = true
TemplateSrc— Source of template for this reporter
(default) | character vector | string scalar | reporter or report | DOM document or document part
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 is used for this reporter or whose template library contains the template for this reporter
DOM document or document part whose template is used for this reporter or whose template library contains the template for this reporter
The specified template must be the same type as the report to which this
reporter is appended. For example, for a Microsoft® Word report,
TemplateSrc must be a Word reporter template. If
TemplateSrc property is empty, this reporter uses the default
reporter template for the output type of the report.
TemplateName— Name of template for this reporter
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
TemplateSrc) for this reporter.
LinkTarget— Hyperlink target for this reporter
(default) | character vector | string scalar |
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 is converted to a
LinkTarget object. The link target immediately
precedes the content of this reporter in the output report.
Add content to chapter
|(Not recommended) Add content to chapter|
Get chapter title reporter
|Create copy of reporter object and make deep copies of property values that reference a reporter, ReporterLayout, or DOM object|
|Get DOM implementation for this reporter|
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.
addmethod is not recommended
Not recommended starting in R2020b
Starting in R2020b, use the
append method instead of the
add method to add content to objects of these Report API classes:
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
classes. Report API programs that use the
add methods will continue
To update existing code, replace the method name
append as shown by the examples in the table.
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);