6

As we know that in TikZ, if unit is not mentioned in the coordinate in TikZ, it takes cm by default.

When I extract the coordinates, I was expecting the unit as cm. But TikZ shows the unit in the coordinate as pt.

How does TikZ determine the unit of measure in a coordinate if no unit is specified.

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\tikzset{zigzag/.style={decorate,decoration=zigzag}}
\begin{document}

\newdimen\XCoord
\newdimen\YCoord
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}

\begin{tikzpicture}
  \coordinate (c) at (0,-2);
  \coordinate (d) at (4,-2);
  \coordinate (e) at (2,-4);
  \draw[thick,red,zigzag,postaction={
    decoration={
        markings,
        mark=at position 0.7 with { \coordinate (x); },
        mark=at position 0.5 with { \coordinate (singularity); },
    },
    decorate
  }] (-2,0) coordinate(a) -- (2,0) coordinate(b);

  \draw[thick,fill=blue!20] (c) -- (b) -- (d) -- (e) -- cycle;
  \draw[thick,postaction={
    decoration={
        markings,
        mark = at position 0.7 with \coordinate (y);
    },
    decorate
  }] (a) -- (c);
  \draw[thick,red,dashed] (x) -- (y);

  \node[above = 10ex of singularity,red] (sn) {singularity};
  \draw[red,->] (sn) -- ($(singularity)+(0,1)$);
  \ExtractCoordinate{x};
  \node[above] at (\XCoord,\YCoord) {(\XCoord,\YCoord)};
\end{tikzpicture}

\end{document} 

enter image description here

subham soni
  • 9,673
  • Not an answer, but the information may be useful: https://tex.stackexchange.com/a/20069/579 – barbara beeton Feb 28 '19 at 03:33
  • Barbara I would like to know the default unit of measure when unit of measure is not mentioned – subham soni Feb 28 '19 at 03:35
  • 1
    Internally TikZ works with pt. You have a coordinate system in which the unit vectors have length 1cm. Does that make sense? The IMHO clearest discussion on this can be found at https://tex.stackexchange.com/a/31606/121799 . –  Feb 28 '19 at 03:38
  • How did you measure the distance though? How did you make sure you are not magnifying the document when measuring? – zyy Feb 28 '19 at 03:39
  • @zyy As far as I can see, there is only the word singularity, not a real singularity, so you can use the Euclidean metric to a good approximation. ;-) –  Feb 28 '19 at 03:41
  • @marmot so if Unit of measure is not mentioned, it take pt by default. Is that right ? – subham soni Feb 28 '19 at 03:44
  • @subhamsoni Almost but not quite. If it is a vector with components (x,y), then this vector will become x e_x + y e_y where e_x=(1cm,0) and e_y=(0,1cm) by default. On the other hand, if you say something like [xshift=7] then this will produce a shift by 7pt. So, in a way, for vectorial quantities the default are cm (in the above sense). Effectively 1 in \draw circle(1); gets also interpreted as 1cm. But I cannot express it better than LoopSpace in https://tex.stackexchange.com/a/31606/121799, especially in a comment. –  Feb 28 '19 at 03:50
  • @marmot in that case the system should express in cm. But it is expressed as pt. Which is surprising to me. – subham soni Feb 28 '19 at 04:13
  • Welcome to the club of those who get continuously surprised by TikZ. ;-) More seriously, everything you do with the calc syntax is done in pt unless you explicitly instruct TikZ to behave differently. You can convert the distances in cm if you want, of course. Is this what you are asking? –  Feb 28 '19 at 04:16
  • @marmot meaning with calc the unit of measure changes from cm to pt. Right? – subham soni Feb 28 '19 at 04:22
  • @marmot Oh, sure, you are correct. – zyy Feb 28 '19 at 04:41
  • If you do not provide a unit, as in (2,1), you specify a point in pgf’s xy-coordinate system. By default, the unit x-vector goes 1cm to the right and the unit y-vector goes 1cm upward. (p.122, pgfmanual, v3.1.1) – Paul Gaborit Feb 28 '19 at 07:28

1 Answers1

9

You can always convert everything from pt to cm or back by multiplying by the ratio 1pt/1cm or its inverse. (If that's not what you're after, I will be happy to remove the post.)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\tikzset{zigzag/.style={decorate,decoration=zigzag}}
\begin{document}

\newdimen\XCoord
\newdimen\YCoord
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}

\begin{tikzpicture}
  \coordinate (c) at (0,-2);
  \coordinate (d) at (4,-2);
  \coordinate (e) at (2,-4);
  \draw[thick,red,zigzag,postaction={
    decoration={
        markings,
        mark=at position 0.7 with { \coordinate (x); },
        mark=at position 0.5 with { \coordinate (singularity); },
    },
    decorate
  }] (-2,0) coordinate(a) -- (2,0) coordinate(b);

  \draw[thick,fill=blue!20] (c) -- (b) -- (d) -- (e) -- cycle;
  \draw[thick,postaction={
    decoration={
        markings,
        mark = at position 0.7 with \coordinate (y);
    },
    decorate
  }] (a) -- (c);
  \draw[thick,red,dashed] (x) -- (y);

  \node[above = 10ex of singularity,red] (sn) {singularity};
  \draw[red,->] (sn) -- ($(singularity)+(0,1)$);
  \ExtractCoordinate{x};
  \node[above] at (\XCoord,\YCoord) {%
  (\pgfmathparse{\XCoord*1pt/1cm}\pgfmathprintnumber{\pgfmathresult}\,cm,%
  \pgfmathparse{\YCoord*1pt/1cm}\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,cm)};
\end{tikzpicture}
\end{document} 

enter image description here