Main Content

mlreportgen.report.TableOfContents Class

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

Table of contents reporter

Description

Create a table of contents (TOC) reporter that adds a table of contents to the report. This class inherits from mlreportgen.report.Reporter.

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

Creation

Description

toc = TableOfContents returns a reporter that generates a table of contents (TOC) section for the report. The default template for the TOC section defines the appearance and page layout of the TOC. The TOC section contains a default title and a TOC element that specifies the location of a TOC to be generated, depending on the report output type. The way in which the TOC is generated differs for each report type.

  • HTML — JavaScript copied from the report template to the report generates the TOC when the report is opened in a browser. The script generates the TOC as a collapsible tree. The tree entries are the hyperlinked contents of the HTML heading elements (h1-h6) of the report. The level of an entry in the TOC tree corresponds to the level of the heading element. Chapter and section reporters generate chapter and section titles as heading elements of the appropriate level, so chapter and section titles appear automatically in the TOC. You can also use DOM Heading elements in a report to generate TOC entries.

  • DOCX — The Report Generator rptview function instructs Word to generate the TOC after it opens the report in Word. If you open a report in Word directly, without using rptview, you must update the report document yourself to generate the TOC. See Update Tables of Contents and Generated Lists in Word Documents.

    The TOC is a two-column table. The first column contains the hyperlinked contents of report paragraphs whose outline levels have been set. The outline level determines the formatting of a TOC entry. The second column contains the number of the page on which the corresponding paragraph occurs. Chapter and section reporters generate chapter and section titles as paragraphs with the appropriate level set, so chapter and section titles appear automatically in the TOC. You can also use DOM Heading elements in a report to generate TOC entries.

  • PDF — The table of contents is generated during PDF document generation.

example

toc = TableOfContents(title) creates a TOC that uses the specified title.

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

Properties

expand all

Table of contents title, specified as one of these values:

  • String or character vector

  • 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 vectors, and/or DOM objects

  • TableOfContentsTitle reporter

Example: 'TableOfContents','Report Contents'

Number of heading levels to use in the table of contents, specified as a positive integer in the range [1,9].

Type of leader to use between the title and the page number, specified as one of these character vectors or string scalars:

  • '.' or 'dots'

  • ' ' or 'space'

This property applies only to PDF reports. Word reports always have a dots leader. HTML reports do not have a leader.

Page layout for the table of contents section, specified as an mlreportgen.report.ReporterLayout object. Use the properties of the ReporterLayout object to override the some of the default page layout properties, such as page orientation.

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

  • 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 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 character vector or string scalar. The template for this reporter must be in the template library of the template source (TemplateSrc) for this reporter.

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID or as 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.

Methods

expand all

Examples

collapse all

Create a table of contents that uses the default formatting.

import mlreportgen.report.*
rpt = Report('output','pdf');
toc = TableOfContents();
add(rpt,toc);

Create a report that includes a table of contents with a title in green. This report also includes chapters, sections, and an appendix section.

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

rpt = Report('Report with TOC');
add(rpt, TitlePage(Title='Report',Subtitle='with TOC'));
toc = TableOfContents;
toc.Title = Text('Table of Contents');
toc.Title.Color = 'green';
toc.NumberOfLevels = 2; 
add(rpt,toc);

ch = Chapter('First Chapter');
add(ch,Section('First Subsection'));
add(ch,Section('Second Subsection'));

add(rpt,ch);
add(rpt,Chapter('Second Chapter'));

add(rpt,PDFPageLayout);
p = Paragraph('Appendix'); 
p.Style = {OutlineLevel(1), Bold, FontSize('18pt')};
add(rpt,p);

close(rpt);
rptview(rpt);

Version History

Introduced in R2017b

expand all