11

I would like to employ TikZ for some constructive work, namely, programming a FabLab laser cutter. This nifty device gets a 2d drawing (as PDF) and cuts along all hairlines in the PDF. A harline is defined as a path with a thickness of 0.01 pt.

However, if I try this with TikZ and pdflatex

\begin{tikzpicture}
    \draw[line width=0.01pt] (0,0) rectangle (1cm,1cm);
\end{tikzpicture}

and open the resulting PDF in Adobe Illustrator, it shows me a line width of 0.0179 pt – way too thick. Seems as if I have reached the limits of TeX.


Edit: The 0.0179 pt were a twofold effect. Firstly, I used pt where I actually should have used 0.01bp, as a the letter unit actually is what everybody else refers to as points. (See What are the possible dimensions / sizes / units LaTeX understands?). Secondly, the PDFs I was analyzing did not came directly out of pdflatex, but where post processed by MacOS, which results in the strange line widths. Thanks Paul!

Remains the generic question about the minimum line width and maximum resolution of TeX.


So what is the minimum line width I can get out of with TeX and TiKZ?

Also, what is this the same as the maximum resolution to place objects?

(For technical drawings, one sometimes has to go down to the µm level, with 1 µm = 0.002845 pt)

Daniel
  • 37,517
  • How can you check the line width with Acrobat ? What is the result of \scoped[transform canvas={scale=.1}] \draw[line width=.1pt] (0,0) rectangle (10cm,10cm); ? Is it the same ? – Kpym Dec 21 '14 at 22:17
  • @Kpym: I have tried it, result the same: 0.0179 pt – Daniel Dec 21 '14 at 22:41
  • If I try tex "\vrule width 1pt height 1sp\bye" the DVI file will contain setrule height 1, width 65536 (this is what dvitype shows). If I change 1sp into 0sp, no setrule command is found (the rule acts like a space, as far as the DVI file is concerned). Then it's left to the printer driver to draw the rule, so it depends on the PDF specifications (and possibly on the printer driver) whether the rule will be visible or not. – egreg Dec 22 '14 at 10:01
  • @egreg: With pdftex the resulting PDF contains a visible line that, according to Adobe Illustrator, is 0 pt thick :-) – Daniel Dec 22 '14 at 14:31

2 Answers2

14

Compile this document via pdflatex:

\documentclass[tikz]{standalone}
\pdfcompresslevel=0
\pdfobjcompresslevel=0
\begin{document}
\begin{tikzpicture}
    \draw[line width=0.01pt] (0,0) rectangle (1cm,1cm);
\end{tikzpicture}
\end{document}

Then search w directives in the PDF (a simple text file). You find:

0.3985 w 
0.00995 w 

The first occurrence is the default line width (=~ .4pt) of TikZ.

The second occurrence is the line width used by the drawn rectangle. You are right: it is not 0.01 but 0.00995.

If you use line width=0.01004pt in your document, you get exactly 0.01 in the PDF file (0.01004/72.27*72=.0100024906600249063...).

(look at What are the possible dimensions / sizes / units LaTeX understands?, especially pt and bp units...)

Edit:

The minimum non null line width produced by TikZ is 0.00003pt (0.00002 w in PDF).

Note: null line width has special meaning in PDF (as in PostScript).

Extract from PDF 32000-1:2008: 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.

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • Aaarg! I know that TeX points are not points. How could I forget that... – Daniel Dec 21 '14 at 22:43
  • Wow, nice detective work :) – percusse Dec 21 '14 at 22:48
  • Hm... that yields 0.18 pt in Adobe Illustrator (which makes sense, if the previous result was 0.179). Something strange is going on... – Daniel Dec 21 '14 at 22:57
  • 2
    Alright, I found the culprit: I did all my tests with LaTeXit, which is kind of nice for small tests. However, if one saves the PDF, LaTeXit apparently pipes it through the MacOS Quartz engine, which caused the effect. If I compile with pdflatex directly, it works: 0.1004pt (or simpler: 0.01bp) gives the right thickness. – Daniel Dec 21 '14 at 23:03
3

I'm not sure at all how you are determining the width of the line segment, but, unless you need the line to be exactly 0.01pt in width, TikZ certainly allows you to construct lines with extremely narrow widths

% arara: pdflatex
% arara: pdflatex
% arara: open

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \foreach \myn in {0,1,2,3,4,5,6,7,8,9}
  {
    \pgfmathsetmacro\mypt{0.01pt - 0.00\myn pt}
    \typeout{===>myn=\myn:\mypt}
    \draw[line width=\mypt pt]
       (0,\myn/400) -- (0.125,\myn/400);
  }
\end{tikzpicture}


\end{document}
A.Ellett
  • 50,533
  • This yields lines with 0.0179, 0.0161, ..., 0.0107, ..., 0,0018 pt. The 0.0107 comes pretty close, have to try if that works. – Daniel Dec 21 '14 at 22:41