how to add title/caption to FormalTable ?

I want to add caption/title to the table. I am making tables using FormalTable but could not find the property to add caption to it. Please help

 Réponse acceptée

Srijith Kasaragod
Srijith Kasaragod le 23 Nov 2021

0 votes

Hi Srushti,
Please refer this answer which captures the same issue.
Regards.

4 commentaires

SRUSHTI KHATAU
SRUSHTI KHATAU le 23 Nov 2021
Thank you for replying. I have had seen that but BaseTable does not have properties like FormalTable.
Could you please show the example where we can add
table = mlreportgen.report.BaseTable(content)
content = mlreportgen.dom.FormalTable object
Please provide small example
Srijith Kasaragod
Srijith Kasaragod le 25 Nov 2021
Modifié(e) : Srijith Kasaragod le 25 Nov 2021
Base table provides an option to specify a numbered title to the table. So inorder to add a title to a Formal table, you can first create a Formal table and then create a Base table from it. The following piece of code shows an example:
import mlreportgen.dom.*
import mlreportgen.report.*
%Create a report
rpt = Report("mydoc","pdf");
open(rpt);
%Create a FormalTable
t = FormalTable({'Col1', 'Col2'}, {'entry11', 'entry12'; 'entry21', 'entry22'});
tableStyles = { ColSep("solid"), ...
RowSep("solid"), ...
Border("solid"), ...
Width("4in")};
% Specify styles for the header first row
headerRow = t.Header.Children(1);
headerRow.Style = [headerRow.Style {Bold()}];
%Create BaseTable from FormalTable and add to report
chapter = Chapter();
chapter.Title = "Table example";
add(rpt,chapter);
table = BaseTable(t);
table.Title = "Formal table to Base table";
add(rpt,table);
%Close and view report
close(rpt);
rptview(rpt);
Hope this helps!
SRUSHTI KHATAU
SRUSHTI KHATAU le 25 Nov 2021
Thank you so much.
Randolph Leiser
Randolph Leiser le 16 Déc 2024
Modifié(e) : Randolph Leiser le 17 Déc 2024
This answer works if you want to do minimal formatting, but BaseTable seems to overwrite or not fully interpret the settings of a Table or FormalTable. For example if we change the style lines of your table creation to:
t.TableEntriesStyle = { ColSep("none"), ...
RowSep("none"), ...
Border("none"), ...
Width("1in")};
then executing the code yields a table with only the bottom and right border removed.
Similarly, trying dashed
t.TableEntriesStyle = { ColSep("dashed"), ...
RowSep("dashed"), ...
Border("dashed"), ...
Width("1in")};
gives this table
I am not sure if there is a way to maintain the formatting of the original table better, as BaseTable does not have Border properties than can be modified.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by