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.
Row[Table[Graphics[Rectangle[{0, 0}, {2^k, 1}]], {k, 0, 5}]]

yields

enter image description here

However, I'd like uniform scaling of the rectangles, i.e., each rectangle should look twice the width (but same height) as its predecessor. How can I force "absolute sizing" here?

Second, how can I align the bottoms of the rectangles? I tried inserting Alignment->Bottom in several spots, none of which worked.

share|improve this question
    
I also find it strange that it is keeping the widths constant, but scaling the heights even though it is the widths that are increasing with k. –  JohnD Nov 9 '12 at 19:42

2 Answers 2

up vote 7 down vote accepted

Row will resize anything that doesn't already have a size attribute set. By setting the imageheight for each graphics object but keeping the width Automatic, you get what you are looking for:

Row[Table[Graphics[Rectangle[{0, 0}, {2^k, 1}], ImageSize -> {Automatic, 25}, PlotRangePadding -> None], {k, 0, 5}]]

enter image description here

Since they are all the same height, they are all automatically aligned properly. If they weren't, I couldn't get Row to align them properly, but Grid did the trick easily.

Grid[{Table[Graphics[Rectangle[{0, 0}, {2^k, 1}],PlotRangePadding -> None], {k, 0, 5}]},  Alignment -> {Left, Bottom}]

gives this: enter image description here

share|improve this answer
2  
My experience is that you can also control the spacing between elements a lot better with Grid than with Row. (Are we all agreed that GraphicsGrid is a trainwreck?) –  user4368 Nov 9 '12 at 19:56
2  
Yes, GraphicsGrid = trainwreck with maximal carnage, IMO. –  JohnD Nov 9 '12 at 20:52
    
Jason, I still don't get why the first rectangle won't cooperate: Grid[{Table[Graphics[Rectangle[{0, 0}, {2^-k, 1}], PlotRangePadding -> None], {k, 0, 5}]}, Alignment -> {Left, Bottom}] –  JohnD Nov 9 '12 at 20:55
1  
@texasAUtiger, from what I can tell, Grid and Row will resize anything that doesn't have its ImageSize set already. So I would still set them so they all have the same height: Grid[{Table[Graphics[Rectangle[{0,0},{2^(-k),1}],PlotRangePadding->None,ImageSiz‌​e->{Automatic,25}],{k,0,5}]},Alignment->{Left,Bottom}] –  user4368 Nov 9 '12 at 21:18
    
Jason, try e.g. Row[(*list*), Spacer[5]] –  Mr.Wizard Nov 10 '12 at 9:12

You could specify the PlotRange explicitly as follows:

Row[Table[
  Graphics[Rectangle[{0, 0}, {2^k, 1}], 
   PlotRange -> {{0, 2^5}, {0, 1}}], {k, 0, 5}]]

example

share|improve this answer
    
I'd need to avoid the large gaps of white space in this solution. –  JohnD Nov 9 '12 at 19:43

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.