Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to build a grid to look like the top-left table shown below, but without an outside frame.

enter image description here

Here is what I've tried to do:

a = {
    {, , 2, 2, 2, 2,},
    {, , 3, , 2, 0, 3},
    {, 2, 2, , 3, , 3},
    {2, 2, 2, , , , 2},
    {2, 3, , , 1, ,},
    {2, , 1, 3, , ,},
    {3, 3, 3, 2, 3, , 3}
    };

f = Riffle[#, "\[CenterDot]", {1, -1, 2}] &;

f /@ Transpose[f /@ a] // Transpose // Grid

enter image description here

What I don't like in my result is that I have three times more dots than I need. And I don't know how to fix it. Suggestions?

share|improve this question
2  
You could replace the extra dots with spaces, by inserting this between Transpose and Grid: MapIndexed[If[OddQ@Total@#2, " ", #1] &, #, {2}] & –  Rahul Narain Dec 26 '12 at 3:04
    
Unfortunately, something like Grid[a, Frame -> All, FrameStyle -> Dashing[{0, 15.1}]] cannot be used here effectively, as it dots are too small and setup requires manual experimentation with the magic number on each platform. –  István Zachar Dec 26 '12 at 15:58

3 Answers 3

Maybe

evenrows = Prepend[#, " "] & /@ (Join @@ Thread[{#, " "}] & /@ a);
oddrows = (Join @@ ConstantArray[{"\[CenterDot]", " "}, 8]);
Grid@Riffle[evenrows, {oddrows}, {1, -1, 2}]

enter image description here

?

share|improve this answer

Yet another option:

  Grid[SparseArray[
  {{i_, j_} /; OddQ[i] && OddQ[j] :> "\[CenterDot]",
   {i_, j_} /; EvenQ[i] && EvenQ[j] :> a[[i/2, j/2]]}
  , {2 Length[a] + 1, 2 Length[a] + 1}, ""]]
share|improve this answer

Depending on what you are doing, this might be better solved by using Graphics commands and building the display as a graphics object rather than a textural output. This however does the trick with just inserting elements into the grid shape:

 gridDots[a_] := Module[{
   rowspacing = Riffle[#, " ", {1, 1 + Last@Dimensions[a] 2, 2}] &,
   colspacing = Riffle[#, {Flatten[ConstantArray[{".", " "}, 1 + Last@Dimensions@a]]},
                        {1, 1 + 2 First@Dimensions@a , 2}] &},
 colspacing[rowspacing /@ a]
 ]

 gridDots[a] // Grid

grid of numbers with dots intserted

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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