Create a table that contains text and figures using the reporting toolbox

2 visualizzazioni (ultimi 30 giorni)
Hi! I am using your reporting function but I have had struggles building a scheme 2 by 2 where positions 1 and 4 are figures, and positions 2 and 3 text.
I have this code:
tp = TitlePage();
tit = Paragraph("Presentación del Primer Trimestre de 2024:");
tit.Style = {HAlign("left"),FontFamily("sans-serif"),...
FontSize("45pt"),Color("white"),...
BackgroundColor("#0072BD"),...
OuterMargin("0in","0in",".5in","1in"),...
HAlign("center")};
tp.Title = tit;
add(rpt, tp);
%% my code to create figures - plots
var_name = ['fig', num2str(j),'Img'];
eval([var_name, ' = Image(getSnapshotImage(Figure(fig), rpt));']);
% Close the figure to avoid accumulation
close(fig);
end
% % % % % % % % ================================ PAGE 1 ===============================
br = PageBreak();
intro1 = HTML(['<p style="white-space:pre; font-size: 25px; font-family: sans-serif;">', ...
'SOMETHING.</p>',...
]);
append(rpt, intro1)
lo_table1 = Table({
fig1Img, fig2Img; ...
fig3Img, []});
lo_table1.entry(1,1).Style = {Width('8in'), Height('3.8in')};
lo_table1.entry(1,2).Style = {Width('8in'), Height('3.8in')};
lo_table1.entry(2,1).Style = {Width('8in'), Height('3.8in')};
lo_table1.entry(2,2).Style = {Width('8in'), Height('3.8in')};
lo_table1.Style = {Width('100%'), ResizeToFitContents(true)};
add(rpt, lo_table1);
% % % % % % % % ================================ PAGE 2 ===============================
% Define the HTML content for the text cells
PAR1 = HTML(['<p style="white-space:pre; font-size: 25px; font-family: sans-serif;">', ...
'SOMETHING.</p>',...
]);
PAR2 = HTML(['<p style="white-space:pre; font-size: 25px; font-family: sans-serif;">', ...
'SOMETHING.</p>',...
]);
lo_table2 = Table({ fig4Img, PAR1);...
PAR2, fig5Img});
lo_table2.entry(1,1).Style = {Width('8in'), Height('3.8in')};
lo_table2.entry(1,2).Style = {Width('8in'), Height('3.8in')};
lo_table2.entry(2,1).Style = {Width('8in'), Height('3.8in')};
lo_table2.entry(2,2).Style = {Width('8in'), Height('3.8in')};
lo_table2.Style = {Width('100%'), ResizeToFitContents(true)};
add(rpt, lo_table2);
br2 = PageBreak();
append(rpt,br2)
close(rpt);
rptview(rpt);
My problem is that the figures appears in my PDF report. But the text does not.
How can I solve it?
Thanks in advance.
  2 Commenti
Manikanta Aditya
Manikanta Aditya il 22 Mar 2024
The issue might be with the way you’re adding the HTML content to the table. Instead of using the 'HTML' function, try using the 'Text' function to add text to your report.
Jonathan
Jonathan il 26 Mar 2024
Modificato: Jonathan il 26 Mar 2024
Thank you for your answer.
I tried but it does not look so goood. Can I adjust some features in text inside a Table like the size of the container of the text e.g that is centered,
Im using this code: I tried to modify the entry 1,2 and 2,1 but it does not work.
% Define the HTML content for the text cells
par1 = Text('La inflación de alimentos se revisa a la baja en la primera parte del horizonte por menores choques de oferta. Se mantienen efectos moderados del fenómeno de El Niño.');
par2 = Text('Se siguen manteniendo presiones de costos sobre la inflación de regulados ante los mayores precios esperados de la energía eléctrica.');
lo_table2 = Table({fig4Img, par1;...
par2, fig5Img});
lo_table2.entry(1,1).Style = {Width('8in'), Height('3.8in')};
lo_table2.entry(1,2).Style = {Width('4in'), Height('3.8in')};
lo_table2.entry(2,1).Style = {Width('8in'), Height('3.8in')};
lo_table2.entry(2,2).Style = {Width('8in'), Height('3.8in')};
lo_table2.Style = {Width('100%'), ResizeToFitContents(true)};

Accedi per commentare.

Risposte (1)

Swastik Sarkar
Swastik Sarkar il 22 Ago 2024
I noticed that, by following @Manikanta Aditya's suggestion, the text was successfully rendered in the PDF. However, there are still some challenges in styling the text to meet the requirements, such as adjusting the text size and centering it.
To modify text properties such as "FontSize," "Color," and alignment, the "StyleClass" in MATLAB's "mlreportgen" package can be utilized. For more information, refer to the following MATLAB documentation:
Here is an example report that demonstrates how to center text using the "HAlign" and "VAlign" properties. Below is the corresponding sample MATLAB code:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('MyReport', 'pdf');
rpt.Layout.PageSize = PageSize("13in", "20in", "landscape");
imgStyle = {ScaleToFit(true)};
% Generate figures and save them as images
for j = 1:2
fig = Figure(surf(peaks(unifrnd(10,20,1))));
var_name = ['fig', num2str(j), 'Img'];
eval([var_name, ' = Image(getSnapshotImage(fig,rpt));']);
eval([var_name, '.Style = imgStyle']);
delete(gcf);
end
PAR1 = Paragraph('La inflación de alimentos se revisa a la baja en la primera parte del horizonte por menores choques de oferta. Se mantienen efectos moderados del fenómeno de El Niño.');
PAR2 = Paragraph('Se siguen manteniendo presiones de costos sobre la inflación de regulados ante los mayores precios esperados de la energía eléctrica.');
cellTextStyle = {HAlign('center'), VAlign('middle'), Width('4in'), Height('3.8in')};
cellImageStyle = {HAlign('center'), VAlign('middle'), Width('8in'), Height('3.8in')};
lo_table2 = Table({fig1Img, PAR1; PAR2, fig2Img});
lo_table2.entry(1, 1).Style = cellImageStyle;
lo_table2.entry(1, 2).Style = cellTextStyle;
lo_table2.entry(2, 1).Style = cellTextStyle;
lo_table2.entry(2, 2).Style = cellImageStyle;
lo_table2.Style = {Width('100%')};
add(rpt, lo_table2);
close(rpt);
rptview(rpt);
I hope this helps.

Tag

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by