Skip to main content
15 events
when toggle format what by license comment
Jan 10, 2018 at 20:48 comment added Jason Gross With[{nmax = 10}, Graphics[Table[ With[{v = StringJoin @@ Table["a", Mod[n, 2, 1]*10]}, Inset[Text[v], Offset[ImageDimensions[ImageCrop[Graphics[Text[v]]]]/2, {0, n/nmax}], {0, 0}]], {n, 1, nmax}]]] has all of the text horizontally aligned on the left, which is what I expect when I specify that the x-location text-width/2 should line up with the center of the text. However, neither one of these works with pdf export (see mathematica.stackexchange.com/questions/163457/…)
Jan 10, 2018 at 20:40 comment added Chris Degnen @JasonGross Can you please add here as a comment the code that gives the correctly aligned graphic because it is not clear what you mean.
Jan 10, 2018 at 17:54 comment added Jason Gross This answer seems incorrect. When I do With[{nmax = 10}, Graphics[ Table[With[{v = StringJoin @@ Table["a", Mod[n, 2, 1]*10]}, Inset[Text[v], Offset[Rasterize[Text[v], "RasterSize"]/2, {0, n/nmax}], {0, 0}]], {n, 1, nmax}] ]] my text is misaligned. The other answer gives a correctly aligned graphic.
Mar 16, 2015 at 22:02 comment added Isaac @alancalvitti: I think I just ended up using pixels/image size rather than coordinates, but I don't remember for sure.
Mar 16, 2015 at 17:21 comment added alancalvitti @Isaac, did you ever get a direct answer in coordinate units? I've asked a similar Q about extracting bounding boxes and still looking for a general method.
Feb 14, 2012 at 5:39 vote accept Isaac
Feb 13, 2012 at 7:19 comment added Szabolcs @Isaac It should have been possible to do it with ExportPacket and PageWidth -> Infinity, but I failed: library.wolfram.com/conferences/devconf99/hintonimportexport/…
Feb 13, 2012 at 7:18 comment added Szabolcs @Isaac I was writing up another answer but I realized that it would not add too much, so I only want to mention that Offset coordinates are important here: text = Style["how quickly daft jumping zebras vex", FontFamily -> "Verdana", FontSize -> 20]; box = Rasterize[text, "BoundingBox"][[1 ;; 2]]; Graphics[ {Text[text, {0, 0}, {-1, -1}], EdgeForm[Thin], FaceForm[None], Rectangle[{0, 0}, Offset[box, {0, 0}]]}, PlotRange -> All ]
Feb 13, 2012 at 6:45 comment added Isaac @AndyRoss: That did it!
Feb 13, 2012 at 2:35 comment added Andy Ross You can also use the option LineBreakWithin -> False in the options passed to Style if line wrapping is what you are trying to avoid.
Feb 13, 2012 at 0:46 comment added Isaac The problem is the line wrapping—I want the width of the rendered text all on one line, but Rasterize[] is wrapping the text at the width of the window.
Feb 13, 2012 at 0:44 comment added Chris Degnen @ Isaac - You can inset the resultant graphics into another graphic using coordinates, e.g. Graphics[{Red, Rectangle[{0, 0}, {1, 0.2}], Inset[%, {0, 0}, {0, 0}]}, PlotRange -> {{0, 1}, {0, 0.2}}, ImageSize -> 400]
Feb 13, 2012 at 0:34 comment added Isaac Actually... it looks like it's rasterizing the output form of the Text[] command: i.sstatic.net/YkeeK.png is the output of Rasterize[Text[Style["Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris varius imperdiet lectus nec bibendum. Maecenas felis ipsum, elementum mattis tristique id, mollis a nisl. Nulla magna dolor, ullamcorper eleifend posuere non, vehicula ut augue.", FontFamily -> "Hypatia Sans Pro", FontSize -> 20], {0, 0}, {0, 0}]], so Rasterize[..,"RasterSize"] gives {724, 104} which isn't the length of the text on a single line...
Feb 13, 2012 at 0:22 comment added Isaac I can definitely use this to get the job done, but it's in terms of image size/pixels, rather than coordinates...
Feb 13, 2012 at 0:03 history answered Chris Degnen CC BY-SA 3.0