座標単位はptですが、TikZではデフォルトはcmです。

座標単位はptですが、TikZではデフォルトはcmです。

ご存知のとおり、TikZ では、TikZ の座標に単位が指定されていない場合は、cmデフォルトで単位が使用されます。

座標を抽出するとき、単位は であると予想していましたcm。しかし、TikZ は座標の単位を と表示しますpt

単位が指定されていない場合、TikZ は座標の測定単位をどのように決定しますか。

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} 

ここに画像の説明を入力してください

答え1

比率またはその逆数を掛けることで、いつでもすべてを pt から cm へ、またはその逆へ変換できます1pt/1cm。(それが目的ではない場合、投稿を削除させていただきます。)

\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} 

ここに画像の説明を入力してください

関連情報