Main Content

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.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

ch = mlreportgen.report.Chapter creates a reporter that generates a chapter. The chapter has a new page layout defined by the default template of the reporter.

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.

ch = mlreportgen.report.Chapter(title) creates a chapter with the specified title. See the Title property.

example

ch = mlreportgen.report.Chapter(Name=Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Properties

expand all

Chapter title, specified as one of these values:

  • String scalar or character vector

  • DOM element object

  • 1-by-N or N-by-1 array of string scalars or DOM element objects

  • 1-by-N or N-by-1 cell array of string scalars, character vectors, and/or DOM element objects

  • SectionTitle reporter returned by the getTitleReporter method

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 element 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.

Whether to number this chapter, specified as true or false. If the value of Numbered 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 Numbered is false, this chapter is not numbered. The value of the Numbered property overrides the numbering specified for all report chapters by the mlreportgen.report.Chapter.number method.

Data Types: logical

Content of the section, specified as one of these values:

  • String scalar or character vector

  • DOM element objects that can be added to a DOM document part

  • Reporters, including Section reporters

  • 1xN or Nx1 array of string scalars or character vectors

  • 1xN or Nx1 cell array of string scalars, character vectors, and/or DOM element objects

Use the Chapter constructor or append method to set this property. You cannot set it directly.

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

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 you append this report. 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.

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.

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.

Methods

expand all

Examples

collapse all

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 R2017b

expand all