How to center FormalImage in report

17 ビュー (過去 30 日間)
GGHao
GGHao 2019 年 7 月 24 日
回答済み: Mary Abbott 2019 年 7 月 25 日
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

回答 (1 件)

Mary Abbott
Mary Abbott 2019 年 7 月 25 日
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';

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by