Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have drawn the following picture:
100% zoom

As you can see, at 100% magnification, the borders of the L and R sections look pretty poorly drawn; They seem to blend into the adjacent background colors (cyan/white, orange/white).

When I try to investigate this by zooming to 1000%, I see that the blending of colors is reduced to a small fraction of the border's width, but still visible:
1000% zoom

Zoomed in all the way to 6400%, the glitch seems to become even smaller, relative to the line width. But they still don't disappear:

  • TOP:
    6400% zoom, top half
  • BOTTOM:
    6400% zoom, bottom half

How does this happen? How can I prevent it? Will it become apparent in a printed (100% zoom) version? If so, under what circumstances?

My code:

\documentclass[border=10pt]{standalone}
\listfiles
\usepackage{tikz}
\usetikzlibrary{calc,chains,scopes,shapes.misc,backgrounds}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\begin{tikzpicture}[start chain,
    node distance=5mm,
    every node/.style={on chain},
    connect/.style={join=by ->},
    point/.style={coordinate},
    l/.style={line width=0, fill=cyan!50, rounded rectangle, rounded rectangle right arc=0, append after command={% <= for the border
        \pgfextra{\begin{pgfinterruptpath}\begin{pgfonlayer}{foreground}
            \draw[] let \p1=($(\tikzlastnode.north east)+(0,-0.5\pgflinewidth)$),
                \p2=($(\tikzlastnode.north west)+(0,-0.5\pgflinewidth)$),
                \p3=($(\tikzlastnode.south west)+(0,0.5\pgflinewidth)$),
                \p4=($(\tikzlastnode.south east)+(0,0.5\pgflinewidth)$),
                \n1={0.5*(\y2-\y3)} in
                (\p1) -- (\p2) arc(90:270:\n1) -- (\p4);
        \end{pgfonlayer}\end{pgfinterruptpath}}
    }},
    c/.style={line width=0, fill=green!50, append after command={% <= for the border
        \pgfextra{% 
            \begin{pgfinterruptpath}\begin{pgfonlayer}{foreground}
            \draw[] let \p1=($(\tikzlastnode.north east)+(0,-0.5\pgflinewidth)$),
                \p2=($(\tikzlastnode.north west)+(0,-0.5\pgflinewidth)$),
                \p3=($(\tikzlastnode.south west)+(0,0.5\pgflinewidth)$),
                \p4=($(\tikzlastnode.south east)+(0,0.5\pgflinewidth)$) in
                (\p1) -- (\p2) (\p3) -- (\p4);
            \end{pgfonlayer}\end{pgfinterruptpath}
        }
    }},
    r/.style={line width=0, fill=orange!50, rounded rectangle, rounded rectangle left arc=0, append after command={% <= for the border
        \pgfextra{% 
            \begin{pgfinterruptpath}\begin{pgfonlayer}{foreground}
            \draw[] let \p1=($(\tikzlastnode.north east)+(0,-0.5\pgflinewidth)$),
                \p2=($(\tikzlastnode.north west)+(0,-0.5\pgflinewidth)$),
                \p3=($(\tikzlastnode.south west)+(0,0.5\pgflinewidth)$),
                \p4=($(\tikzlastnode.south east)+(0,0.5\pgflinewidth)$),
                \n1={0.5*(\y1-\y4)} in
                (\p3) -- (\p4) arc(-90:90:\n1) -- (\p2);
            \end{pgfonlayer}\end{pgfinterruptpath}
        }
    }}
]
\node[point] (p1) {};
\node [l, connect] (l) {L};
{[node distance=0]
\node [c] (c) {C};
\node [r] (r) {R};
}
\node[point, connect] (p2) {};
\end{tikzpicture}
\end{document}

PS: I used TikZ 2013/12/13 v3.0.0 (rcs-revision 1.142), and pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9 64-bit) to create the PDF. Screenshots are taken of an Adobe Reader 10.1.7.

share|improve this question
    
There is no problem here with same versions of packages except I'm running on TexLive 2013 and Ubuntu 13.10 . –  ferahfeza Feb 21 at 17:07
2  
When things are overlaid, the way an item is rendered can cause these artifacts (which often disappear under closer magnification). –  Steven B. Segletes Feb 21 at 17:32

1 Answer 1

up vote 9 down vote accepted

The PDF page description code for the lines around the node is:

27.96689 6.52524 m
20.89789 6.52524 l
17.29405 6.52524 14.37263 3.60384 14.37263 0.0 c
14.37263 -3.60384 17.29405 -6.52524 20.89789 -6.52524 c
27.96689 -6.52524 l 
S  
41.80336 6.52524 m
27.96689 6.52524 l
27.96689 -6.52524 m
41.80336 -6.52524 l
S 
41.80336 -6.52524 m
49.97934 -6.52524 l
53.58318 -6.52524 56.5046 -3.60384 56.5046 0.0 c
56.5046 3.60384 53.58318 6.52524 49.97934 6.52524 c
41.80336 6.52524 l 

m: moveto
l: lineto
c: curveto
S: stroke

The points, where the left and right parts meet the middle lines are:

  • (27.96689, ±6.52524)
  • (41.80336, ±6.52524)

The point, where two lines are touching each other, is exact the same in all cases. The line width does not change at all. Therefore it is an artifact of the PDF viewer.

It can be avoided by drawing a continuous line:

\documentclass[border=10pt]{standalone}
\listfiles
\usepackage{tikz}
\usetikzlibrary{calc,chains,scopes,shapes.misc,backgrounds}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\begin{tikzpicture}[start chain,
    node distance=5mm,
    every node/.style={on chain},
    connect/.style={join=by ->},
    point/.style={coordinate},
    l/.style={
      line width=0,
      fill=cyan!50,
      rounded rectangle,
      rounded rectangle right arc=0,
    },
    c/.style={
      line width=0,
      fill=green!50,
    },
    r/.style={
      line width=0,
      fill=orange!50,
      rounded rectangle,
      rounded rectangle left arc=0
    },
]
\node[point] (p1) {};
\node [l, connect] (l) {L};
{[node distance=0]
\node [c] (c) {C};
\node [r] (r) {R};
}
\node[point, connect] (p2) {};

\draw
  let
    \p1=($(l.north west)+(0,-0.5\pgflinewidth)$),
    \p2=($(l.south west)+(0,0.5\pgflinewidth)$),
    \n1={0.5*(\y1-\y2)},
    \p3=($(r.north east)+(0,-0.5\pgflinewidth)$),
    \p4=($(r.south east)+(0,0.5\pgflinewidth)$),
    \n2={0.5*(\y3-\y4)}
  in
    (\p1)
    arc(90:270:\n1)
    -- (\p4)
    arc(-90:90:\n2)
    -- cycle
;
\end{tikzpicture}
\end{document}

Result

share|improve this answer
    
Excellent answer. The advantage I see in not drawing a single closed path is that I don't need to worry about borders when/after drawing the segments. –  derabbink Feb 21 at 19:57

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.