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.

Note: this problem is no longer present in version 10.


Exporting the following as a PDF file

Graphics[{
  {Red, Rectangle[{0, 0}, {1, 1}]},
  {Green, Rectangle[{1, 0}, {2, 1}]}
}]

does not produce perfectly tiled rectangles, and some of the corners are cut too, as shown here:

rectangle with dog-ear, first example

and here:

rectangle with dog-ear, second example

Is this a bug?

I solve the problem by giving them some tiny edges:

Graphics[{
  EdgeForm[{Red, Thickness[Tiny]}],
  {Red, Rectangle[{0, 0}, {1, 1}]},
  EdgeForm[{Green, Thickness[Tiny]}],
  {Green, Rectangle[{1, 0}, {2, 1}]}
}]

The rectangles are slightly larger, and their sizes are slightly different; practically this isn't a problem. But is there a more elegant solution?

share|improve this question
2  
I believe that, yes, it is a bug--in the Mac OS Preview app, which employs a rather confusing interpolation algorithm to what is displayed. As I don't have a Mac, I can't confirm that this is definitely a duplicate of that question, but the PDF output (from version 8) is certainly correct for me on Windows when using SumatraPDF, Adobe Reader, and Acrobat Pro. –  Oleksandr R. Apr 25 '13 at 18:02
1  
The problem is still there in my Adobe Reader 10.1.6: see here. –  Taiki Apr 25 '13 at 18:54
2  
Hmm, I see. This problem seems to have appeared in version 9 or 9.0.1. Okay, looks like Mathematica's bug, then--especially considering its absence in previous versions. –  Oleksandr R. Apr 25 '13 at 19:07
2  
A workround is to export as EPS, then open EPS in Preview - seems to convert without that problem... –  cormullion Apr 25 '13 at 19:16
2  
Deleting the green square in Illustrator still leaves a slightly larger green frame: imgur.com/x0BNyO6 It would probably be good if you could report this to support@wolfram.com –  Szabolcs Apr 25 '13 at 21:33
show 3 more comments

2 Answers 2

up vote 5 down vote accepted

Unfortunately some effects, such as transparency, are not supported in EPS, so that workaround is not always usable. I found a different workaround with different tradeoffs:

  • instead of Rectangle use Polygon
  • specify the colours using the VertexColors option of Polygon

The polygons will be correct size and will not overlap when exported to PDF. However, they will be broken up into triangles, and depending on the PDF viewer the seams may be subtly visible, especially if the polygons are transparent.

Examples:

t1 = Normal@
  Graphics[GraphicsComplex[
    Tuples[Range[5], 2], {Opacity[0.5], 
     Polygon[#, 
        VertexColors -> ConstantArray[RandomReal[1, 3], 4]] & /@ Join @@ Table[{1, 2, 5 + 2, 5 + 1} + i + j, {i, 0, 3}, {j, 0, 3*5, 5}]}]]


t2 = Normal@
  Graphics[GraphicsComplex[
    Tuples[Range[5], 
     2], {Opacity[0.5], {RGBColor @@ RandomReal[1, 3], Polygon[#]} & /@
       Join @@ Table[{1, 2, 5 + 2, 5 + 1} + i + j, {i, 0, 3}, {j, 0, 3*5, 5}]}]]

t1 will export as precisely sized rectangles while t2 will export as overlapping rectangles.

Zoomed in:

enter image description here

share|improve this answer
add comment

Please let me compile answers from the comments so that this topic can be marked as answered.

  1. Yes, this is a bug.

  2. A better solution than having rectangles of slightly different sizes and slightly larger than desired is to export the figure as EPS first and then convert it to PDF later. The cut corners are still there though.

share|improve this answer
    
As an alternative answer, you could try the function rasterTrick in my answer here. The output of Export["file.pdf",graphics//rasterTrick] looks fine to me using version 9.0.1 on OS X (where graphics is the original example in your question) –  Jens Jul 2 at 22:39
add comment

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.