Main Content

mlreportgen.report.Section Class

Namespace: mlreportgen.report
Superclasses: mlreportgen.report.Reporter

Section reporter

Description

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

The mlreportgen.report.Section class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

section = Section creates a reporter that generates a report section. You can add the section reporter to a report, chapter, or another section. 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. The size of the title diminishes by default with the depth of the section in the report hierarchy up to five levels deep. Titles of sections lower than 5 are not numbered and have the same font size as level 5.

section = Section(title) creates a report section containing a section title with the specified title text. 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 up to five levels deep.

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

example

Properties

expand all

Section title, specified as one of these values:

  • character vector or string scalar

  • DOM element object

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

  • 1-by-N or N-by-1 cell array of strings, character vectors, and/or DOM element 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 mlreportgen.report.Section.number method.

Data Types: logical

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

  • String or character vector

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

  • Reporters, including Section reporters

  • 1xN or Nx1 array of strings or character vectors

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

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

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

  • Document Object Model (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 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.

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

theReport = Report("SectionExampleReport","pdf");

append(theReport,TitlePage(Title="Report with Sections"));

append(theReport,TableOfContents);
 
theChapter = Chapter("Images");
append(theChapter,Section(Title="Boeing 747",Content=Image("BoeingSectionExample.jpg")));
append(theChapter,Section(Title="Peppers",Content=Image("PeppersSectionExample.png")));
append(theReport,theChapter);

close(theReport);
rptview(theReport);

Here are the sections with the images in the generated report.

  • This example uses a DOM Text object to define the title. By using the DOM element object, you can set its properties and override the default black color of the section title.

    import mlreportgen.report.*
    import mlreportgen.dom.*
    
    rpt = Report('New Report','pdf');
    open(rpt)
    sect = Section;
    sect.Title = Text('A Section');
    sect.Title.Color = 'blue';
    append(rpt,sect);
    
    close(rpt)
    rptview(rpt)
    

    Example of title defined as "A Section" in displaying in blue

Create a HTML Report and set the subsection titles to center alignment.

import mlreportgen.report.*
import mlreportgen.dom.*

rpt = Report('My Report','html');
append(rpt,TitlePage(Title='My Report'));
append(rpt,TableOfContents);
chTitle = Heading1('Chapter ');
chTitle.Style = {CounterInc('sect1'),...
     WhiteSpace('preserve')...
     Color('black'),...
     Bold, FontSize('24pt')};
append(chTitle,AutoNumber('sect1'));
append(chTitle,'. ');

sectTitle = Heading2();
sectTitle.Style = {CounterInc('sect2'),...
     WhiteSpace('preserve') ...
     HAlign('center'),PageBreakBefore};
append(sectTitle,AutoNumber('sect1'));
append(sectTitle,'.');
append(sectTitle,AutoNumber('sect2'));
append(sectTitle,'. ');
title = clone(chTitle);
append(title,'Images');
ch = Chapter(Title=title);
title = clone(sectTitle());
append(title,'Boeing 747');
append(ch,Section(Title=title,Content=Image(which('b747.jpg'))));
title = clone(sectTitle());
append(title,'Peppers');
append(ch,Section(Title=title,Content=Image(which('peppers.png'))));

append(rpt,ch);
close(rpt);
rptview(rpt);

section_rptr_ex_3.png

Version History

Introduced in R2017b