This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page. class


Section reporter


Create a section reporter that adds a section to the report. This class inherits from


section = Section() creates a reporter that generates a report section. You can add the section reporter to a report, chapter, or another section. You can add up to 6 section levels to a chapter. If you add a section to a report, the section starts on a new, portrait page with default margins and a page number in the footer. The page number equals the previous page number plus one. If you add the section to a chapter or another section, the reporter creates a subsection that continues on the current page.

A hierarchical section number prefixes the title text by default. For example, the default number of the first subsection in the second chapter is 2.1. The font size of the title diminishes by default with the depth of the section in the report hierarchy. You can add up to five section levels to the hierarchy.

section = Section(title) creates a report section containing a section title with the specified title text.

section = Section(Name,Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order. Enclose each property name in single quotes.

Input Arguments

expand all

See Title property.


expand all

Section title, specified as one of these values:

  • String or character array

  • DOM object

  • 1-by-N or N-by-1 array of strings or DOM objects

  • 1-by-N or N-by-1 cell array of strings, character arrays, and/or DOM objects

  • SectionTitle reporter

Inline objects are objects that a paragraph can contain. If the title value is an inline object, the section object uses one template from a set of templates. Templates are stored in the template library for the section. The template used to create the title depends on whether the title is numbered and the section level in the section hierarchy. Use the Numbered property to specify whether the section title is numbered.

If the title value is a DOM paragraph or other DOM block object, the section inserts the object at the beginning of the section. If you use a DOM block object, you can use block elements to customize the spacing, alignment, and other properties of the section title. In this case, you must fully specify the title format and provide title numbering yourself.

Choice to number this section, specified as a logical. If the value of this property is [] or true, the section is numbered relative to other sections in the report. The section number appears in the section title. If the value is false, this section is not numbered. The value of this Numbered property overrides the numbering specified for all report sections by the method.

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

  • String or character array

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

  • Reporters, including Section reporters

  • 1xN or Nx1 array of strings or character arrays

  • 1xN or Nx1 cell array of strings, character arrays, and/or DOM objects

Use the Section constructor or add method to set this property. You cannot set it directly.

Source of template for this reporter, specified as one of these values:

  • String or character array specifying the path of the file containing the template for this reporter

  • Reporter or report whose template is used as the template for this reporter or whose template library contains the template for this reporter

  • DOM document or document part whose template is used as the template for this reporter or whose template library contains the template for this reporter

The specified template must be of the same type as the report to which this reporter is appended. For example, for a 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 template for this reporter, specified as a string or character array. The template for this reporter is in the template library of the template source (TemplateSrc) for this reporter.

Hyperlink target for this reporter, specified as a string or character array that specifies the link target ID, or an mlreportgen.dom.LinkTarget object. A string or character array value is converted to a LinkTarget object. The link target object immediately precedes the content of this reporter in the output report.


add Add section content
createTemplateCreate section template
customizeReporter Create custom section reporter class
getClassFolderSection class definition file location
getTitleReporter Get section title reporter
numberSet section numbering

Inherited Methods

getImpl Get implementation of reporter

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).


Add Title and Image to a Report Section

Create report sections and add them to a chapter.

import mlreportgen.dom.*

rpt = Report('My Report', 'pdf');
add(rpt, TitlePage('Title', 'My Report'));
add(rpt, TableOfContents);

ch = Chapter('Images');
add(ch, Section('Title',  'Boeing 747', ...
    'Content', Image(which('b747.jpg'))));
add(ch, Section('Title',  'Peppers', ...
    'Content', Image(which('peppers.png'))));
add(rpt, ch);


Use DOM Text Object as a Section Title

Use a DOM Text object to define the title and override the color of a section title.

import mlreportgen.dom.*
sect = Section;
sect.Title = Text('A Section');
sect.Title.Color = 'blue'; % Overrides default color (black)

Change Alignment of a Section

This example generates a report that sets the subsection titles to center alignment.

import mlreportgen.dom.*

rpt = Report('My Report','html');
add(rpt,TitlePage('Title','My Report'));
chTitle = Heading1('Chapter ');
chTitle.Style = {CounterInc('sect1'),...
     Bold, FontSize('24pt')};
append(chTitle,'. ');

sectTitle = Heading2();
sectTitle.Style = {CounterInc('sect2'),...
     WhiteSpace('preserve') ...
append(sectTitle,'. ');
title = clone(chTitle);
ch = Chapter('Title',title);
title = clone(sectTitle());
append(title,'Boeing 747');
title = clone(sectTitle());


Introduced in R2017b