MatLab Report Generator Word Wrap Issues

조회 수: 16 (최근 30일)
Matt O'Brien
Matt O'Brien 2022년 11월 25일
댓글: Paul Kinnucan 2025년 7월 28일
I have a pdf generated via MatLab Report Generator. I have a few remaining issues. I have spent days trying to resolve via search of this and other forums.
I am posting each issue individually.
This issue. Word Wrap at the end of a line in a table.
I am successfully populating a table with text and the table is placed as I wish on the page. The problem is that words are truncated at the end of a line and then continue on the next. I wish to use the behaviour where words are not split at the end of a line before any combination of cr/lf.
Ps. These settings make no difference.
MyDescrTbl.Style = {Hyphenation(true)};
or
MyDescrTbl.Style = {Hyphenation(false)};

채택된 답변

Sameer Pujari
Sameer Pujari 2022년 11월 28일
Hi Matt
To get the text to wrap to the second line by separating at a "space" rather than in the middle of a word when using the MATLAB Report Generator, you need to customize the default PDF template used by performing the following:
1. Create a new PDF template from the default PDF template:
>> mlreportgen.dom.Document.createTemplate('mytemplate','pdf');
2. This creates a new PDF template file, "mytemplate.pdftx". Then unzip the template, to gain access to the "root.css" file which allows you to define PDF styles:
>> unzipTemplate('mytemplate.pdftx')
3. In the new folder that is created go to the "stylesheets" folder and open "root.css" to edit in MATLAB or in a text editor.
4. Add the following style to the "table" entry in the CSS file:
-ah-word-break: keep-all
5. Save the CSS file and now zip the template to create an updated "mytemplate.pdftx" file:
>> zipTemplate('mytemplate.pdftx');
6. Then create a "Report" object, by passing the new template as an input argument:
>> d = Report("mydoc","pdf", "mytemplate.pdftx");
For more information on creating a PDF template please visit the following documentation link:
For more information on the different styles you can modify for a PDF template please visit the following documentation link:
  댓글 수: 5
Matthew Penning
Matthew Penning 2024년 11월 4일
Hello,
Currently I am not able to get this solution to work for me. Was wondering if maybe when I was setting the column and row styles it would override this? Any suggestions? Below is a snip of the code where I am styling the table - in case there is anything in there that may be conflicting.
reftbl = Table([header;row]); % Create the table
%Style overall table
reftbl.Style = {OuterMargin('0pt', '0pt', '0pt', '10pt'), ... % Set table margins
Width('100%')}; % Set table width
reftbl.TableEntriesStyle = {Border('solid','black','1')};
reftbl.HAlign = 'center'; % Center align the table
%Style columns
groups(1) = TableColSpecGroup();
for ww = 1:8
specs(ww) = TableColSpec();
specs(ww).Style = { HAlign('Center'),FontSize('8pt') };
end
groups(1).ColSpecs = specs;
reftbl.ColSpecGroups = groups;
%style top row
topRow = reftbl.Children(1,1);
topRow.Style = {BackgroundColor('lightgrey'),Bold(true)};
Paul Kinnucan
Paul Kinnucan 2025년 7월 28일
The following example shows how to enable word break programmatically:
import mlreportgen.dom.*
d = Document("brkrpt","pdf");
t = Table({"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec malesuada est posuere, dapibus ipsum vitae, ultrices neque. Ut vulputate purus nunc, quis ultrices lectus facilisis nec. Pellentesque scelerisque sagittis tempor. Donec blandit lobortis diam, eget gravida mi porttitor vitae. Etiam porttitor, tellus vitae facilisis faucibus, felis est aliquam velit, consectetur pharetra metus nunc eu nisi. Suspendisse potenti. Ut vel nibh ipsum. Phasellus eget egestas lorem."});
t.Style = {ResizeToFitContents(false), FOProperties(FOProperty('ah-word-break','keep-all'))};
append(d,t);
close(d);
rptview(d);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by