6

Hej everybody! :)

I'm currently taking my first steps with TikZ, and when trying to plot some simple rectangle shapes I noticed a rather weird effect that occurs when I try to fill the rectangles with a hatch pattern. Sometimes (!), the hatch pattern doesn't fill the rectangle all the way and there is some small margin:

Here is a minimal working example that demonstrates the effect. I have compiled it on both on my own system (MacTeX 2014, tikz.sty from 2013/12/13, i.e. v3.0.0 (rcs-revision 1.142)) and on Overleaf.com. The result is the same.

\documentclass{article}

\usepackage{float}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{filecontents}{rectangles.tikz} 
    \begin{tikzpicture}
        \draw[] (0,0) rectangle (2,2);
        \draw[pattern=north east lines] (0,0) rectangle (1,2);
    \end{tikzpicture}
\end{filecontents} 

\begin{document}
    \subsection*{Effect, version 1:}
    \lipsum[2]
    \begin{figure}[H]    
        \centering
        \input{rectangles.tikz}
        \caption{Test Caption 1.}
    \end{figure}
    \lipsum[3]    
    \subsection*{Effect, version 2:}
    \begin{figure}[H]
        \input{rectangles.tikz}
        \caption{Test Caption 2.}
    \end{figure}
\end{document}

As I said, the effect does not always occur. For example, if I position my first figure using \begin{figure}[t], everything looks fine. I therefore suspect that the effect depends on the (absolute) position of the tikzpicture on the page?

Any information about why this is happening, or even better, how you can prevent this from happening, would be greatly appreciated :)

Edit: I am sorry, perhaps I was not clear enough perviously. By "margin", I mean that the pattern in the hatched part of the rectangle does not reach all the way to the border:

(I marked the critical/questionable area of the image in red.)

Edit 2: After doing some more research on incompatibilities between TikZ and Mac Preview, I also found this thread which basically describes the same problem: Incompatibility with TikZ and Mac OS X Preview [closed]

It therefore really seems like this is an older problem with the PDF rendering engine, and not TikZ. I filed a bug report to Apple and also posted the problem description to the Apple Support Community to maybe give a clue to people with the same or similar problems :)

der_herr_g
  • 280
  • 2
  • 9
  • I'm using v3.0.1a of TikZ (the latest version on CTAN), and I can't replicate the issue. The pattern on both rectangles goes all the way to the edges. – JP-Ellis Feb 06 '16 at 10:40
  • 1
    @ChristianHupfer The issue isn't that half the rectangle is filled, but that the pattern doesn't fill the half properly and doesn't reach the edge fully. Compare the two pictures in the question. – JP-Ellis Feb 06 '16 at 10:48
  • 2
    Curiously, @der_herr_g, do you see this effect in all PDF viewers, and even if you zoom in a lot? I have occasionally encountered issues similar to that which were due to the PDF not being rendered properly. – JP-Ellis Feb 06 '16 at 10:51
  • @JP-Ellis: Ah, now I get it, at the bottom of the rectangle –  Feb 06 '16 at 10:51
  • @ChristianHupfer: Yes, the issue is the bottom of the hatched rectangle, like JP-Ellis kindly explained. I edited my question to make this more clear :) – der_herr_g Feb 06 '16 at 10:54
  • 1
    @JP-Ellis: Very good point actually! If I open the PDF with OSX Preview, Fileloupe, or the built-in PDF preview of Texpadapp, there is a margin. If I open it in Acrobat Reader or Chrome, everything looks like it should. – der_herr_g Feb 06 '16 at 10:59
  • 1
    @der_herr_g Thanks for checking. If the first three programs all use the same backend, then I would say that this is a bug in this backend and a bug report can be filed (if one doesn't exist already). – JP-Ellis Feb 06 '16 at 11:06
  • @JP-Ellis: I did some more research (c.f. my second edit), and it really appears to be a bug in the OS X PDF renderer. If you post this as an answer, I will accept it :) – der_herr_g Feb 06 '16 at 14:09
  • Cheers :) Glad we could find the cause of this issue. – JP-Ellis Feb 06 '16 at 14:12

1 Answers1

4

As discussed in the comments above, at appears this is actually a bug in a PDF renderer on OS X used by FileLoupe and the built-in PDF viewer of the TeXPad App.

JP-Ellis
  • 8,929
  • 2
  • 33
  • 49