3
$\begingroup$

I have a table in Mathematica as a list of lists.

How to export the table, and force Mathematica to insert as many spaces as needed between columns so that columns are aligned?

For example,

Export["~/Desktop/test.txt", {{2334252, 1}, {2, 235211234}}, "Table"]

gives a misaligned table. The misalignment depends on the tab size of your editor

$\endgroup$
  • $\begingroup$ How about adding some sample data? $\endgroup$ – Yves Klett Feb 4 '15 at 16:54
  • $\begingroup$ @YvesKlett I added an example. How bad the misalignment looks depends on the tab size, of course. $\endgroup$ – becko Feb 4 '15 at 17:11
  • $\begingroup$ Any preference for the aligning (left/center/right)? $\endgroup$ – Yves Klett Feb 4 '15 at 17:16
  • $\begingroup$ @YvesKlett I just found a way to do it and posted an answer. However, ideally I would like to specify different alignments for different columns. $\endgroup$ – becko Feb 4 '15 at 17:19
3
$\begingroup$

I figured it out.

Export["~/Desktop/test.txt", {{2334252, 1}, {2, 235211234}}, "Table",
  "FieldSeparators"->" ", Alignment->Left]

Instead of Left you can also use Center/Right. The options for Export with different formats aren't very easy to find in the documentation!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.