在 tikzpicture 中,我可以将 1pt 设置为单位,但 1px 不起作用!所以我猜 1pt 等于 1px。但听起来差不多,但不完全一样!
这是示例。原始图像为 200x150,但节点显示为 200.74948ptx150.5621pt!
它应该正好是 200x150 吗?获得 200x150 的正确方法是什么?
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[x=1pt,y=1pt]
%image source: /usr/local/texlive/2017/texmf-dist//latex/mwe/example-image-4x3.png
\node[anchor=south west,inner sep=0,outer sep=0] (image) at (0,0)
{\includegraphics{example-image-4x3}};
\draw[line width=0.1pt] let
\p1=(image.south west),
\p2=(image.north east),
\n1={(\x2-\x1)},
\n2={(\y2-\y1)}
in node[anchor=west] at (0,120) {\large \n1,\n2};
\end{tikzpicture}
\end{document}
答案1
我不能告诉你为什么这种情况确实会发生,但我前段时间偶然发现了这一点,至少当时我不知道是否有更深层次的原因。如果你在网上查找转化率,你会发现
1cm = 28.3465pt (in web).
然而,Ti钾Z 声称,如下面的 MWE 所示,
1cm = 28.45274pt (Ti*k*Z).
如果考虑到这个微小的差异,您会在舍入误差范围内得到完美匹配,如以下输出中最下面的一行所示。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[x=1pt,y=1pt]
%image source: /usr/local/texlive/2017/texmf-dist//latex/mwe/example-image-4x3.png
\node[anchor=south west,inner sep=0,outer sep=0] (image) at (0,0)
{\includegraphics{example-image-4x3}};
\draw[line width=0.1pt] let
\p1=(image.south west),
\p2=(image.north east),
\n1={(\x2-\x1)},
\n2={(\y2-\y1)}
in node[anchor=west] at (0,120) {\large \n1,\n2};
\path let \p1=(1cm,0) in node[anchor=west,fill=white] at (0,90) {$\x1\ne 28.3465pt$};
\pgfmathsetmacro{\myconv}{28.3465pt/28.45274}
\draw[line width=0.1pt] let
\p1=(image.south west),
\p2=(image.north east),
\n1={(\x2-\x1)*\myconv},
\n2={(\y2-\y1)*\myconv}
in node[anchor=west] at (0,40) {\large \n1,\n2};
\end{tikzpicture}
\end{document}