Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell (thanks to Sjoerd C. de VriesSjoerd C. de Vries),

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell (thanks to Sjoerd C. de Vries),

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell (thanks to Sjoerd C. de Vries),

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

added 83 characters in body
Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 297

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell (thanks to Sjoerd C. de Vries),

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell,

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell (thanks to Sjoerd C. de Vries),

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

added 1203 characters in body
Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 297

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell,

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

This is the best way to get the size of the text cell,

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

The width returned by Rasterize is not always correct, as you found out, and since you aren't going to Rasterize before building your tree then the size of the raster graphics is irrelevant in this case.

This is the best way to get the size of the text cell,

{w1, h1} = ImageDimensions@ImageCrop@Graphics@ExpBox[Fooooo/2];
{w2, h2} = ImageDimensions@ImageCrop@Graphics@ExpBox[Bar];

Of course, you can just grab the width by using First as in your code, but I also noticed that the height needs adjusting in the latter case.

Then you can plot

With[{h = Max[{h1, h2}]},
 
 Graphics[{ExpBox[Fooooo/2, {w1/2, 0}], ExpBox[Bar, {w1 + w2/2, 0}]}, 
  PlotRange -> {{0, w1 + w2}, h {-.5, .5}}, 
  ImageSize -> {w1 + w2, h}]
 ]

enter image description here

I'm the type that always makes a function for something I'm doing more than twice, so you can wrap it all up like this:

combBoxes[exps__] := Module[{widths, heights, boxes, totalsize},
  {widths, heights} = 
   Transpose@(ImageDimensions@ImageCrop@Graphics@ExpBox@# & /@ {exps});
  heights = {Total@widths, Max@heights};
  widths = 
   Total[widths[[;; #]]] - widths[[#]]/2 & /@ Range@Length@widths;
  boxes = ExpBox[#1, {#2, 0}] & @@@ Transpose[{{exps}, widths}];
  Graphics[boxes, 
   PlotRange -> {{0, heights[[1]]}, heights[[2]] {-.5, .5}}, 
   ImageSize -> heights]
  ]

combBoxes[Foooooo/2, Bar]
combBoxes[This, is, how, I, would, make, these, boxes, 
 FooooooooBaaarrrrr^2/2]

enter image description here

Source Link
Jason B.
  • 70.2k
  • 3
  • 144
  • 297
Loading