필터 지우기
필터 지우기

How to center FormalImage in report

조회 수: 7 (최근 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 CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by