Create a table that contains text and figures using the reporting toolbox
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
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.
Risposte (1)
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.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!