Filter löschen
Filter löschen

How to aappend Image with caption in Paragraph using mlreportgen while generating report?

7 Ansichten (letzte 30 Tage)
I want to add image with caption in the paragraph. Caption property is available in FormalImage but, can not append that in paragraph. For appending image in paragraph we need to use Image with does not have caption feature.
Please help me with this. Thank you.

Antworten (1)

Kausthub am 12 Feb. 2024
Hi Srushti,
I believe that you would like to add an image with a caption in the paragraph. Yes, you are right about "Image" not having the option to add the caption but you could split the paragraph into parts and add the "FormalImage" in between them.
A snippet for the same:
import mlreportgen.dom.*;
% Create the report
rpt ='output','docx');
% Create the chapter
chapter =;
chapter.Title = 'Image with Caption within a Paragraph';
% Create the paragraph
p = Paragraph(['Lorem ipsum dolor sit amet, consectetur adipiscing elit,' ...
' sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ...
' Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris' ...
' nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in' ...
' reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla' ...
' pariatur. Excepteur sint occaecat cupidatat non proident, sunt in' ...
' culpa qui officia deserunt mollit anim id est laborum.']);
% Add the paragraph
image =;
image.Image = which('ngc6543a.jpg');
image.Caption = 'Cat''s Eye Nebula or NGC 6543';
image.Height = '5in';
% Add the image
% Add the second paragraph
% Add the chapter
Also, I have added the screenshot of the created document for your reference.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by