使用 指定给定坐标上方节点的高度时,无需声明单位above
。第 17 章第 5.3 节中以下示例中的注释表明,数字 0.2(未提及单位)被渲染为TikZ
0.2 厘米(或 2 毫米)。
\begin{tikzpicture}
\draw[help lines] (0,0) grid (2,2);
\node at (1,1) [above=0.2, draw] {above};
% south border of the node is now 2mm above (1,1)
\end{tikzpicture}
以下代码与手册中的代码类似,除了[x=2cm,y=2cm]
,它会放大图形。第一个节点使用 定位above=0.25
,节点的下边缘位于坐标上方 0.5 厘米处;第二个节点使用 定位above=0.25cm
,节点的下边缘位于坐标上方 0.25 厘米处。手册中哪里讨论了这种区别?
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,shapes,positioning,intersections,quotes,decorations.markings}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\draw (0,0) grid [xstep=0.5, ystep=0.5] (2,2);
\node at (0.5,1) [above=0.25, draw] {over};
\node at (1.5,1) [above=0.25cm, draw] {over};
\end{tikzpicture}
\end{document}
答案1
差异是由于\begin{tikzpicture}[x=2cm,y=2cm]
,它告诉 TikZ 在没有明确尺寸的情况下使用 2cm 的增量。在您的示例中,above=0.25
意味着与 相同yshift=0.25*2cm,anchor=south
。请注意,这仅在您加载positioning
库时才会发生。以下示例可能有助于澄清。
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{positioning}
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm]
\draw (0,0) grid [xstep=1, ystep=1] (4,4);
\node at (0.5,1) [blue,above=1, circle, draw] {over};
\node at (1.5,1) [red,yshift=1cm,anchor=south, circle, draw] {over};
\node at (2.5,1) [above=1cm, draw] {over};
\node at (3.5,1) [above=10mm, draw] {over};
\end{tikzpicture}
\quad
\begin{tikzpicture}[x=2cm,y=2cm]
\draw (0,0) grid [xstep=1, ystep=1] (4,4);
\node at (0.5,1) [blue,above=1, circle, draw] {over};
\node at (1.5,1) [red,yshift=1cm,anchor=south, circle, draw] {over};
\node at (2.5,1) [above=1cm, draw] {over};
\node at (3.5,1) [above=10mm, draw] {over};
\end{tikzpicture}
\end{document}