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

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

I 'know nuthink!' about the live editor and definitely no ideas about exporting to pdf inside it, but surely you don't need that many significant digits, do you? How are you preparing the table in MATLAB code to start with? What if you set
format shortG
first?
Its for an assignment for class so I have no say on the number of significant digits. I've done
format long;
right at the top of the file so that all the numbers are displayed, and when showing the table i use
x = 1:0.1:5; % any array
y = exp(x); % another array
table(x', y', 'VariableNames', {'X', 'Y'})
ans = 41×2 table
X Y ___ ________________ 1 2.71828182845905 1.1 3.00416602394643 1.2 3.32011692273655 1.3 3.66929666761924 1.4 4.05519996684467 1.5 4.48168907033806 1.6 4.95303242439511 1.7 5.4739473917272 1.8 6.04964746441295 1.9 6.68589444227927 2 7.38905609893065 2.1 8.16616991256765 2.2 9.02501349943412 2.3 9.97418245481472 2.4 11.0231763806416 2.5 12.1824939607035
for all my tables.
format long;
"right at the top of the file..."
Yes, that causes the large number of digits, but is it actually a stated requirement of the assignment?
Never using live scripts, and the few times I've attempted the interface isn't at all intuitive (to me at least) I dunno.
I did some report building with the report generator and when stuck on how to accomplish something found the AI 'bot generally gave sufficient guidance that could then at least find the relevant documentation even if the code itself didn't work. If it isn't prohibited by your ground rules, mmight try that to see what hints it might provide.
"... is it actually a stated requirement of the assignment?" Yup -_-, we're given a skeleton and not allowed to change anything.
I tried the bot, but it said basically the same thing of changing the format. I think what i'll to is export it to latex and fiddle with there.
Thanks for your help though, at least now I know for future assignments :D
The 'bot says you can adjust the column widths interactively in the live script and the pdf doc will honor those. Have you tried that?
Otherwise, <old threads on Answers? are that only programmatic way would be to use the DOM report generator which is undoubtedly ouf of scope for a homework assignment unless it is on using report generator.
I'm aware that i can adjust them interactively, I just wanted to know if there was a better way to achive that. Exporting to latex/html and printing to PDF from there does the job (from what I've tried to do)
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.
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

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

"... there is no direct way to solve this issue when exporting directly to PDF,"
Programmatically, other than DOM, that appears to be so, but...
Doesn't the interactive setting in the live script work? I was presuming the point was to turn in a report of the homework solution achieved using live scripts; doesn't that (presuming it does work) meet the assignment?
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; the major complaint I had while still consulting was the the least productive use of limited customer resources was in such trivia.
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 :)
"...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)

Products

Release

R2024a

Asked:

on 13 Feb 2026

Edited:

dpb
on 14 Feb 2026

Community Treasure Hunt

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

Start Hunting!