15

Hello I am trying to create a figure with tikz. Im using patterns to define a few different regions. zone 0 is gray zone 1 is north east lines z2 is north west lines

For some reason the diagonal patterns are coming out dashed. And Im not sure why. Does anyone know how to fix this?

Below is my code and a screen shot:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\begin{document}
  \begin{tikzpicture}
    \tkzInit[xmax=5,ymax=5]
    %\tkzAxeXY
    %zone 2 (rectangle, negative)
    \fill[pattern=north west lines] (0,5) rectangle (5.5,0);
    %circle mask
    \fill[white] (4,1.5) circle (1.35);
    %zone 1
    \node[minimum width=2.7cm,
    circle,inner sep=0pt,fill opacity=1,
    line width=2.5mm,pattern=north east lines,opacity=1] at (4,1.5){};
    %zone 0 (positive)
    \node[minimum width=2cm,
    circle,inner sep=0pt,fill opacity=1,
    line width=2.5mm,draw=gray,opacity=1] at (4,1.5){};
    %wall (dashed line)
    \node[minimum width=2cm,
    circle,inner sep=0pt,fill opacity=0,
    line width=.5mm,dashed,draw=black,opacity=1] at (4,1.5){};
  \end{tikzpicture}
\end{document} 

Bad Lines

jmerkow
  • 283
  • 1
    Welcome to TexSE! I wonder what version of TikZ you are using? On my plain TexLive 2014 system (Mac OSX) the diagonal lines come out solid. – Thruston Dec 13 '14 at 23:08
  • Is there a way to check? I am using MacTex 2014 and using latexmk to build – jmerkow Dec 13 '14 at 23:36
  • 1
    add \listfiles say before \begin{document}, you will get list of files with version in the log. –  Dec 14 '14 at 00:10
  • tikz.sty 2013/12/13 v3.0.0 (rcs-revision 1.142) – jmerkow Dec 14 '14 at 00:18
  • I think this is a renderer-side problem. I tried exporting PDF to PNG and the latter looks good. (By the way, so are they dashed in tikz manual.) – Symbol 1 Dec 29 '14 at 01:26
  • I don't have problem (lines are solid) when compiling your code with the same TikZ version and PDF/Lua/Xe/LaTex. This is probably a viewer problem. Have you checked with another viewer? – Kpym Dec 29 '14 at 09:02
  • Similar question to: http://tex.stackexchange.com/questions/212551/is-tikz-sending-ambiguous-pdf-instructions-that-only-texstudio-understands-well – SDrolet Mar 28 '15 at 21:57

1 Answers1

15

I think this is a renderer-side problem. For the code at the end, the left one is the screenshot and the right one is the exported PNG.

Here are some code/comment from pgfcorepatterns.code.tex;

% Creates a new colored pattern
%
% [#1] = optional list of variables.
% #2   = pattern name
% #3   = lower left of bounding box
% #4   = upper right of bounding box
% #5   = step vector
% #6   = pattern code
%
% Description:
%
% Declares a new colored pattern. Such patterns have a one or more
% fixed inherent colors. See the pdf-manual for more details on
% uncolored patterns.
%
% The parameters have the same effect as for uncolored patterns.

and code from pgflibrarypatterns.code.tex.

\pgfdeclarepatternformonly{north east lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{4pt}{4pt}}{\pgfqpoint{3pt}{3pt}}%
{
  \pgfsetlinewidth{0.4pt}
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
  \pgfpathlineto{\pgfqpoint{3.1pt}{3.1pt}}
  \pgfusepath{stroke}
}

So I think this is what happened

and what I did

\documentclass[tikz]{standalone}
    \usepackage{tikz}\usetikzlibrary{patterns}

    \pgfdeclarepatternformonly{south west lines}{\pgfqpoint{-0pt}{-0pt}}{\pgfqpoint{3pt}{3pt}}{\pgfqpoint{3pt}{3pt}}{
        \pgfsetlinewidth{0.4pt}
        \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfqpoint{3pt}{3pt}}
        \pgfpathmoveto{\pgfqpoint{2.8pt}{-.2pt}}
        \pgfpathlineto{\pgfqpoint{3.2pt}{.2pt}}
        \pgfpathmoveto{\pgfqpoint{-.2pt}{2.8pt}}
        \pgfpathlineto{\pgfqpoint{.2pt}{3.2pt}}
        \pgfusepath{stroke}}

\begin{document}
    \begin{tikzpicture}
        \fill[pattern=north east lines](0,1)rectangle(1,0);
        \fill[pattern=south west lines](0,1)rectangle(-1,0);
    \end{tikzpicture}
    \begin{tikzpicture}[line width=.4cm]
        \begin{scope}[opacity=.25]
            \draw[thin](1,2)rectangle(2,1)(1.5,1)node[below]{de facto bounding box};
            \draw[thin](0,3)rectangle(3,0)(1.5,0)node[below]{tessellating box};
            \draw[thin](-1,4)rectangle(4,-1)(1.5,-1)node[below]{bounding box};
            \draw[opacity=0](-1,4)rectangle(4,-1);
            \draw(0,0)--(3.1,3.1);
        \end{scope}
        \clip(1,2)rectangle(2,1);
        \draw(0,0)--(3,3);
    \end{tikzpicture}
    \begin{tikzpicture}[line width=.4cm]
        \begin{scope}[opacity=.25]
            \draw[thin](0,3)rectangle(3,0)(1.5,0)node[below]{bounding box = tessellating box};
            \draw(0,0)--(3,3)(-.2,2.8)--(.2,3.2)(2.8,-.2)--(3.2,.2);
        \end{scope}
        \clip(0,3)rectangle(3,0);
        \draw(0,0)--(3,3)(-.2,2.8)--(.2,3.2)(2.8,-.2)--(3.2,.2);
    \end{tikzpicture}
\end{document}

south east version

For your convenience, here is a south east version

\pgfdeclarepatternformonly{south east lines}{\pgfqpoint{-0pt}{-0pt}}{\pgfqpoint{3pt}{3pt}}{\pgfqpoint{3pt}{3pt}}{
    \pgfsetlinewidth{0.4pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{3pt}}
    \pgfpathlineto{\pgfqpoint{3pt}{0pt}}
    \pgfpathmoveto{\pgfqpoint{.2pt}{-.2pt}}
    \pgfpathlineto{\pgfqpoint{-.2pt}{.2pt}}
    \pgfpathmoveto{\pgfqpoint{3.2pt}{2.8pt}}
    \pgfpathlineto{\pgfqpoint{2.8pt}{3.2pt}}
    \pgfusepath{stroke}}
Symbol 1
  • 36,855
  • When you say "the screen shot", what viewer are you using ? When you say "exported PNG", how you export it ? – Kpym Dec 29 '14 at 09:05
  • @Kpym I am using Preview on OS X. The screenshot is what I saw when I opened the PDF file. And then from menubar File->Export...-> PNG – Symbol 1 Dec 29 '14 at 09:43
  • This looks like an OS X previewer problam, and not a TikZ one for me. You can check your PDF in another viewer (Acrobat/Chrome/...) . – Kpym Dec 29 '14 at 11:17
  • @Kpym I believe it is. On Chrome it looks all right. By the way, it looks good in Finder's quick view. – Symbol 1 Dec 29 '14 at 11:26
  • Similar question to: http://tex.stackexchange.com/questions/212551/is-tikz-sending-ambiguous-pdf-instructions-that-only-texstudio-understands-well – SDrolet Mar 28 '15 at 21:59
  • Can you do one for south east please? – Matthew Tang Feb 08 '17 at 03:23
  • @MatthewTang Is this still a problem? On which machine/PDF reader? – Symbol 1 Feb 08 '17 at 03:41
  • @Symbol 1, on the ShareLatex website. I'm playing around with your code to make the direction north west as we speak. – Matthew Tang Feb 08 '17 at 03:44
  • Thanks. I also happen to have problems with the grid patterns. Please see https://ibb.co/ftWBka – Matthew Tang Feb 08 '17 at 05:51
  • @MatthewTang You may either ask a followup question; or search pgflibrarypatterns.code.tex for the definition of patterns and play with them. – Symbol 1 Feb 08 '17 at 15:18
  • I still have that problem. PGF version 3.0.1, Miktex, in Adobe Reader, Firefox and Poppler (TexStudio). Microsoft Edge seems to be the only exception. – jaytar Sep 22 '17 at 10:41
  • @jaytar You are saying that you have problems with or without my patch? I might not be able to help in either case but maybe ask a new question? – Symbol 1 Sep 22 '17 at 16:15
  • Without that patch. Your patch is fine, but you asked Matthew Tang if the problem persists, and I wanted to give an update. – jaytar Sep 22 '17 at 16:30