Main Content

mlreportgen.report.ListOfCaptions class

Package: mlreportgen.report
Superclasses: mlreportgen.report.Reporter

List of captions reporter

Description

Use an object of the mlreportgen.report.ListOfCaptions class to create a reporter that adds a section for a list of captioned report elements to a report. To create a reporter for a list of figures with captions or tables with titles, use objects of the mlreportgen.report.ListOfFigure and mlreportgen.report.ListOfTables classes, respectively. To create a reporter for a list for other types of report elements, such as equations, use a ListOfCaptions object.

To identify the report elements to include in the list of captions:

  1. Choose a numbering stream name, for example, equation. Set the AutoNumberStreamName property of the ListOfCaptions object to the numbering stream name.

  2. Create captions for the report objects as mlreportgen.dom.Paragraph objects.

  3. Associate the Paragraph objects with the numbering stream name by using an mlreportgen.dom.AutoNumber object.

The generated list of captions contains the captions associated with the specified numbering stream name. The list entries link to the captions in the report. In PDF and Word reports, the list also includes the page numbers of the captions in the report. A leader fills the space between a caption and its page number.

The way the list of captions is generated depends on the report type:

  • PDF — The Report API generates the list during report generation.

  • Word — The Report API generates a placeholder for the list. To generate the list items, you must update the Word document in your report generation program or in Word. See Update a Table of Contents or Generated List in a Word Document.

  • HTML — The Report API generates a placeholder for the list. When the report opens in an HTML browser, the browser generates the list in a sidebar.

Note

You can use a ListOfCaptions reporter for captions that follow a report element or titles that precede a report element.

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

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

example

loc = mlreportgen.report.ListOfCaptions() creates a ListOfCaptions reporter with default property values. Specify the list of captions section title by setting the Title property.

lof = mlreportgen.report.ListOfCaptions(title) creates a ListOfCaptions reporter with the Title property set to the specified title.

lof = mlreportgen.report.ListOfCaptions(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 or double quotes.

Properties

expand all

List of captions section title, specified as one of these values:

  • String scalar or character vector

  • Inline DOM object, such as an mlreportgen.dom.Text object

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

  • 1-by-N or N-by-1 cell array that contains any combination of strings, character vectors, or inline DOM objects

  • mlreportgen.report.Title object returned by the getTitleReporter method

Name of numbering stream, specified as a character vector or string scalar.

Type of leader to use between the caption 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 list of captions section, specified as an mlreportgen.report.ReporterLayout object. Use the properties of the ReporterLayout object to override some of the default page layout properties, such as page orientation.

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

This example generates a section for a list of the captions of the equations in a report. You can use the same procedure to generate a list of captions for other report elements. The example identifies the captions to include in the list by associating the captions with the automatic numbering stream that has the name equation. You can use any name for the numbering stream as long as the name matches the value of the AutoNumberStream property of the ListOfCaptions object that represents the list of captions.

Import the DOM and Report API packages so that you do not have to use long, fully qualified class names.

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

Create a report.

rpt = Report("My Report","pdf");

Add a table of contents to the report.

toc = TableOfContents;
append(rpt,toc);

Create a list of captions section and add it to the report. Specify that the elements to include in the list are associated with the number stream name equation.

loc = ListOfCaptions();
loc.Title = "List of Equations";
loc.AutoNumberStreamName = "equation";
append(rpt,loc);

Create a chapter and add an equation to the chapter.

ch = Chapter("Physics Principles");
eq = Equation("e = m * c^2");
append(ch,eq);

Create a paragraph for the equation caption.

p = Paragraph("Equation ");

Create an automatic numbering stream with the name equation and associate it with the paragraph.

append(p,AutoNumber("equation"));

Increment the counter for the numbering stream.

p.Style = {HAlign("center"),CounterInc("equation"),WhiteSpace("preserve")};

Append the rest of the caption text to the paragraph and append the paragraph to the chapter. Append the chapter to the report.

append(p,' Mass–energy equivalence');
append(ch,p);
append(rpt,ch);

Close and view the report.

close(rpt);
rptview(rpt);

Here is the list of equations in the report:

Introduced in R2020b