How to center FormalImage in report

13 vues (au cours des 30 derniers jours)
GGHao
GGHao le 24 Juil 2019
I am trying to insert a imaging into a Matlab report with class FormalImage. By the default settings, the figure and the caption are left end alignment. How could I set that they can align in center?
The code is
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('ms-report','pdf');
fig = FormalImage(figsnapnm);
fig.Caption = 'DAS Snapshot';
fig.Height = '3in';
add(rpt, fig)
close(rpt)
rptview(rpt)
The figure is
snap.png

Réponses (1)

Mary Abbott
Mary Abbott le 25 Juil 2019
You can create a template based on the default FormalImage template that centers the image and caption.
Create a template based on the default FormalImage template and unzip the template:
mlreportgen.report.FormalImage.createTemplate('centeredImageTemplate', 'pdf')
unzipTemplate('centeredImageTemplate.pdftx', 'centeredImageTemplate_pdftx')
In centeredImageTemplate_pdftx\stylesheets\root.css, add text-align: center; to both FormalImageImage and FormalImageCaption styles:
p.FormalImageImage {
margin-bottom: 10pt;
text-align: center;
}
p.FormalImageCaption {
font-size: 10pt;
color:black;
white-space: pre;
-fo-keep-with-previous.within-page: always;
text-align: center;
}
Zip the template:
zipTemplate('centeredImageTemplate.pdftx', 'centeredImageTemplate_pdftx')
In your code, set the TemplateSrc property of the figure reporter to centeredImageTemplate:
fig = FormalImage(figsnapnm);
fig.TemplateSrc = 'centeredImageTemplate';

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by