4
$\begingroup$

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.

$\endgroup$
6
$\begingroup$

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}.

$\endgroup$
2
  • 2
    $\begingroup$ annoying that Style changes the font isn't it.. fix with {FontFamily -> Times, 30} $\endgroup$ – george2079 Nov 6 '15 at 15:46
  • $\begingroup$ 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. $\endgroup$ – johnny09 Nov 26 '15 at 16:03
4
$\begingroup$
Export["test.png", MatrixForm[ ..] // TraditionalForm, 
         ImageSize -> 500, ImageResolution -> 1000]

enter image description here

$\endgroup$
4
$\begingroup$
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]
$\endgroup$
1
$\begingroup$

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", %];
$\endgroup$
1
$\begingroup$

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}"}];
$\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.