4

Using @m_goldberg's code I have created a matrix with the following command:

MatrixForm[{{n, -1 + n, -2 + n, ⋯, 1}, {2 n, 2 n - 1, 
2 n - 2, ⋯, n + 1}, {3 n, 3 n - 1, 
3 n - 2, ⋯, 
2 n + 1},  {⋮, ⋮, ⋮, ⋱, ⋮}, {n^2, -1 + n^2, -2 + n^2,⋯, 
HoldForm[(n - 1) n + 1]}},   TableAlignments -> {Center, Center}] // TraditionalForm

If I save the output I get a small, low quality PNG picture.

So, is there a way to convert an output to a graph, or enlarge it? So that to get a better and larger picture of a matrix? I would appreciate any hint or suggestion.

Thank you very much.

johnny09
  • 395
  • 2
  • 13

5 Answers5

7

An alternative that produces a sharp image is

m = {{n, -1 + n, -2 + n, ⋯, 1}, 
     {2 n, 2 n - 1, 2 n - 2, ⋯, n + 1}, 
     {3 n, 3 n - 1, 3 n - 2, ⋯, 2 n + 1}, 
     {⋮, ⋮, ⋮, ⋱, ⋮},  
     {n^2, -1 + n^2, -2 + n^2, ⋯, HoldForm[(n - 1) n + 1]}};
Rasterize@Style[MatrixForm[m, TableAlignments -> {Center, Center}] // TraditionalForm), 30]

enter image description here

Then, right-click the image, choose "Save Graphic As...", and store the image in the desired format.

Addendum

In response to the OP's comment below, columns can be given different colors by

clr = {Red, Orange, Green, Blue, Magenta};
Rasterize@Style[MatrixForm[MapIndexed[Style[#1, clr[[Last@#2]]] &, m, {2}], 
    TableAlignments -> {Center, Center}] // TraditionalForm, 30]

enter image description here

Replace Last by First to give rows different colors instead. Also, as noted by george2079 in another comment below, the font can be set by replacing 30 by, for instance, {FontFamily -> Times, 30}.

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
  • 2
    annoying that Style changes the font isn't it.. fix with {FontFamily -> Times, 30} – george2079 Nov 06 '15 at 15:46
  • Thank you very much for your answer. I would like to colour some columns different colours but so far I can only change the colour for the whole matrix. May I ask if there is a way to colour the columns different colours? Thank you again. – johnny09 Nov 26 '15 at 16:03
5
Export["test.png", MatrixForm[ ..] // TraditionalForm, 
         ImageSize -> 500, ImageResolution -> 1000]

enter image description here

george2079
  • 38,913
  • 1
  • 43
  • 110
4
ImageResize[
 Rasterize@(MatrixForm[{{n, -1 + n, -2 + n, ⋯, 1}, {2 n, 2 n - 1, 
     2 n - 2, ⋯, n + 1}, {3 n, 3 n - 1, 3 n - 2, ⋯, 
     2 n + 1},  {⋮, ⋮, ⋮, ⋱, ⋮}, {n^2, -1 + n^2, -2 + n^2,⋯, HoldForm[(n - 1) n + 1]}}, 
     TableAlignments -> {Center, Center}] // TraditionalForm), 500]
bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
David G. Stork
  • 41,180
  • 3
  • 34
  • 96
2

In addition to the various approaches yielding rasterized images, you can use MaTeX to obtain a vector graphics:

yourTable = MatrixForm[{{n, -1 + n, -2 + n, ⋯, 1}, {2 n, 2 n - 1, 
2 n - 2, ⋯, n + 1}, {3 n, 3 n - 1, 
3 n - 2, ⋯, 
2 n + 1},  {⋮, ⋮, ⋮, ⋱, ⋮}, {n^2, -1 + n^2, -2 + n^2,⋯, 
HoldForm[(n - 1) n + 1]}},   TableAlignments -> {Center, Center}] // TraditionalForm;

<< "MaTeX`"
MaTeX[TeXForm[yourTable]]
Export["test.pdf",%]

Here is the result of the above code.

Of course you can combine this with bbgodfrey's answer of using colored columns if you include the color package for latex:

SetOptions[MaTeX, "Preamble" -> {"\\usepackage{color}"}];
Felix
  • 3,871
  • 13
  • 33
1

Edit bbgodfrey's code for having control of resolution and size:

m = {{n, -1 + n, -2 + n, ⋯, 1}, 
     {2 n, 2 n - 1, 2 n - 2, ⋯, n + 1}, 
     {3 n, 3 n - 1, 3 n - 2, ⋯, 2 n + 1}, 
     {⋮, ⋮, ⋮, ⋱, ⋮},  
     {n^2, -1 + n^2, -2 + n^2, ⋯, HoldForm[(n - 1) n + 1]}};

Rasterize[
 Style[MatrixForm[%, TableAlignments -> {Center, Center}] // 
   TraditionalForm], RasterSize -> 1000, ImageSize -> 500]
Export["filename.png", %];
Ben Yu
  • 11
  • 1