[Tex/LaTex] TikZ zero-width line with dashed line

tikz-pgf

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

Best Answer

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