7

When drawing a dashed line, it seems that TikZ inserts a zero-width line that is visible on some (e.g., Acrobat, Sumatra) but not all (e.g., Evince, Chromium browser) PDF viewers.

From the PDF 1.7 specs, section 8.4.3.2:

A line width of 0 shall denote the thinnest line that can be rendered at device resolution: 1 device pixel wide. However, some devices cannot reproduce 1-pixel lines, and on high-resolution devices, they are nearly invisible. Since the results of rendering such zero-width lines are device-dependent, they should not be used.

An almost minimal example:

% Created by tikzDevice version 0.7.3 on 2014-11-02 08:56:28
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage,psfixbb]{preview}
\PreviewEnvironment{pgfpicture}
\setlength\PreviewBorder{0pt}

\begin{document}
  \begin{tikzpicture}[x=1pt,y=1pt]
    \definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
    \definecolor[named]{fillColor}{rgb}{0.00,0.00,0.00}

    \path[draw=drawColor,line width= 0.6pt,dash pattern=on 1pt off 3pt,
          line join=round,fill=fillColor]
      ( 21.13, 19.75) -- (132.49,132.50);
  \end{tikzpicture}
\end{document}

Here's the output as seen in Acrobat XI pro (print-screen, export as PNG looks even worse):

Acrobat screen shot

Is this a known issue? Are there some options missing with the \path command?

Reference: Original issue for the tikzDevice R package.

Perhaps related: TikZ fill zero-width border

1
  • Remove fill=fillColor from your path options... Commented Nov 2, 2014 at 8:29

1 Answer 1

9

Drawing and filling causes the issue, only drawing works as expected:

\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage,psfixbb]{preview}
\PreviewEnvironment{pgfpicture}
\setlength\PreviewBorder{0pt}

\begin{document}
  \begin{tikzpicture}[x=1pt,y=1pt]
    \definecolor[named]{drawColor}{gray}{0}
    \definecolor[named]{fillColor}{rgb}{0,0,0}

    \path[
      draw=drawColor,
      line width= 0.6pt,
      dash pattern=on 1pt off 3pt,
      % line join=round,
      line cap=round,
      % fill=fillColor,
    ]
      ( 21.13, 19.75) -- (132.49,132.50);
  \end{tikzpicture}
\end{document}

Remarks:

  • With a straight line, line join does not make too much sense, therefore I have changed it to line cap.
  • 0 is three bytes shorter than 0.00.

Result

The the fill color is given, also a fill operation is applied to the path as can be shown in the nondegenerated case of a triangle. The example also shows that line join can be used and has its expected effect:

\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage,psfixbb]{preview}
\PreviewEnvironment{pgfpicture}
\setlength\PreviewBorder{0pt}

\begin{document}
  \begin{tikzpicture}[x=1pt,y=1pt]
    \definecolor[named]{drawColor}{gray}{0}
    \definecolor[named]{fillColor}{rgb}{0,0,0}

    \path[
      draw=drawColor,
      line width= 0.6pt,
      dash pattern=on 1pt off 3pt,
      line join=round,
      line cap=round,
      fill=red,
    ]
      (20, 20) -- (60, 60) -- (60, 20) -- cycle;
  \end{tikzpicture}
\end{document}

Result triangle

3
  • Thanks for the ultrafast reply. The TeX code is autogenerated, so some options are indeed redundant. I'll change the code generator.
    – krlmlr
    Commented Nov 2, 2014 at 8:35
  • Just one more question: Do you think it will hurt just to leave line join in the \path declaration? Will there be any difference in the output? (It's autogenerated TeX code after all... ;-) )
    – krlmlr
    Commented Nov 2, 2014 at 8:39
  • @krlmlr line join should not have an effect for single (unconnected) lines. But it is effective, if two line pieces of dashed lines meet in a corner, see updated answer. Commented Nov 2, 2014 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .