Filter löschen
Filter löschen

How to center FormalImage in report

7 Ansichten (letzte 30 Tage)
GGHao
GGHao am 24 Jul. 2019
Beantwortet: Mary Abbott am 25 Jul. 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

Antworten (1)

Mary Abbott
Mary Abbott am 25 Jul. 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';

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by