How to center FormalImage in report

3 visualizaciones (últimos 30 días)
GGHao
GGHao el 24 de Jul. de 2019
Respondida: Mary Abbott el 25 de Jul. de 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

Respuestas (1)

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

Community Treasure Hunt

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

Start Hunting!

Translated by