Exporting a live script as a pdf renders tables with an inconsistent format

49 views (last 30 days)
Hi everyone,
I'm trying to export a live script to a PDF for one of my assignments, but the format of tables that MATLAB renders is inconsistent. With some tables, each numerical value is displayed on one line, while with others, the last digit of the number is split on a second line within the cell. In both cases, the table does not fill the entire page space. I see that I can adjust the column widths manually in the live script, but I was wondering if there is a more succinct way to render the tables so that the numbers are not split across multiple lines.
Attached are screenshots of the correct and incorrectly formatted tables, as well as my export settings.
Any help is appreciated.
  8 Comments
DGM
DGM on 14 Feb 2026 at 14:49
Edited: DGM on 14 Feb 2026 at 14:52
Using format long is similar to using %g with fprintf() in that it does not strictly ensure a fixed field width. It will use fewer digits when it can.
format long
x = (1:3).';
y = [pi 2 2.5].';
table(x,y)
ans = 3×2 table
x y _ ________________ 1 3.14159265358979 2 2 3 2.5
Note that the round-trip conversion (decimal-float64-decimal) of both 2 and 2.5 are exactly representable with fewer digits than the field width implied by something which cannot. This is an emphatic example, but sometimes it cuts neatly at a different number of digits.
That said, I don't know anything about using live scripts, the report generator, or any versions released in the last few years. I'm just suggesting that maybe tailored formatting requirements might need a bit more deliberate construction.
Julian
Julian on 14 Feb 2026 at 15:34
That makes sence, which is wierd considering that depending on how i export the document, the format changes. I think it may be just how the PDF renderer for livescripts interprets the numbers, and that it isn't anything MATLAB specific

Sign in to comment.

Accepted Answer

Julian
Julian on 14 Feb 2026 at 14:36
While i have found that there is no direct way to solve this issue when exporting directly to PDF, exporting to HTML and then printing to PDF from there solves the table issue. The same can be done using LaTeX, although it does change the document style (fonts, etc.), while the HTML preserves it to a degree (code blocks do not fill the width of the page, rather they fill the width of the code).
  3 Comments
Julian
Julian on 14 Feb 2026 at 15:59
In my question I said "I see that I can adjust the column widths manually in the live script". The interactive settings do work, but it means that i must manually adjust every column in every table, of which there are quite a few.
"As per so often the case, one can spend essentially limitless amounts of time just fiddling with how things look rather than actually solving any real problems" I wholeheartedly agree, which is why I wanted a simple solution rather than to manually tweak everything. On the other hand though, the way in which we present results does have an impact on how our work is recieved. I know whomever marks my assignment will get annoyed that many of the tables I present look wierd, and that may distract them from the actual findings.
Thank you once again for your help :)
dpb
dpb on 14 Feb 2026 at 16:45
Edited: dpb on 14 Feb 2026 at 17:39
"...manually adjust every column in every table, of which there are quite a few...."
OK. I also made an unwarranted assumption that for a homework assignment there would be just one or two and one might as well just fixup the table(s) in the script while solving the rest of the problem.
I don't disagree at all about presentation affecting perception; that's what peeved me with reporting results to clients taking so much time to clean up things.
The format long is a real pita kind of thing to put into a script imo -- I don't know that in 30+ years using MATLAB I've ever used it for anything other than debugging things like rounding errors and the like; it's just never possible that more than 5-6 figures can ever be truly significant except, perhaps, in the bowels of some sensitive numerical algorithm.
My thinking is and have suggested to Mathworks the table should be customizable by variable format but so far, not gotten that far even with the uitable. The only way at present to gain more control than the global format setting is as @DGM noted, write a specific format which then means the data in the table itself must all be text, not numeric which is awkward at best.

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!