How to keep formatting when cutting and pasting to office

One thing that I would like to do is cut and paste a table to an email. When I do this however, particularly if a paste more than one table into the same email, the formatting doesn't work. Particularly, the tables will be indented, but the second table will be indented from where the first table is indented, not from the start of the line.
I could paste as text only, but it would be nice to keep the formatting.
I could write to an excel sheet and then paste from there, but i don't know how to keep the formatting doing that.
I asked copilot, but it doesn't know how to help format a document.

2 Comments

From where are you copying and what formatting are you talking about? And what email client are you using/pasting into?
I'm pasting from the command window. The formatting I am talking about is the spacing and bold on the variable and row names. I am pasting into Outlook.
Here is an example:
col1 col2
_______ _______
snap 0.81472 0.91338
crackle 0.90579 0.63236
pop 0.12699 0.09754
and another table
col3 col4
_______ _______
whos 0.2785 0.96489
on 0.54688 0.15761
first 0.95751 0.97059
Here, the line spacing doesn't come over well, but there is no weird indenting.

Sign in to comment.

Answers (2)

The MATLAB command display is a console window while by default Outlook uses HTML. There is no control over the command window formatting other than the number format and spacing controlled by the format command (applies to table display as well) and the choice of fonts. If you haven't, selecting a non-proportional font and compact line spacig may help, but HTML may still not render what is pasted into it in the same visual appearance.
I haven't looked explicitly; you would have to copy and then paste a sample into a text file to poke at to see -- it may be the "extra" spaces are that the command window has the <CR-LF> pair which looks "doubled up".
I doubt there really is anything that can be done with the direct output obtained from scraping the command window output; the intermediary of using an intermediate app is probably only way to be able to format things prettily. You might be able to write some COM-based functions that would do this; I've never looked at the Outlook API,
Try right-clicking in the email and selecting "Keep Source Formatting" under Paste Option in the context menu that comes up.

Products

Release

R2025b

Asked:

on 23 Jan 2026

Answered:

on 26 Jan 2026

Community Treasure Hunt

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

Start Hunting!