更多详情

更多详情

为什么下图中点的标签QR“图钉”之间的距离如此之远?

\documentclass[10pt]{amsart}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}


\begin{document}

\begin{tikzpicture}

%The slope-intercept form for the line k is y = 2x - 6, and the slope-intercept form for
%the line $\ell$ is y = -x + 8. The two lines intersect at (8/3, 16/3). Point Q = (4/3, -10/3)
%is on line k, and point R = (8/3, 16/3) is on line $\ell$. (The diagram is magnified by 1/2.)
\draw[<->] ({(1/2)*(-3/2)},{(1/2)*(-9)}) -- ({(1/2)*15/2},{(1/2)*9});
\node[anchor=south west, inner sep=0, font=\footnotesize] at ($({(1/2)*15/2},{(1/2)*9}) +({atan(2)}:0.15)$){$\ell$};
\draw[<->] ({(1/2)*(-1)},{(1/2)*9}) -- ({(1/2)*19/2},{(1/2)*(-3/2)});
\node[anchor=north west, inner sep=0, font=\footnotesize] at ($({(1/2)*19/2},{(1/2)*(-3/2)}) +({atan(-1)}:0.15)$){\textit{k}};


%P, Q, and R are collinear. P is the midpoint of QR, Q is a point on $\ell$, and
%R is a point on k.
\coordinate (P) at ({(1/2)*2},{(1/2)*1});
\draw[fill] (P) circle [radius=1.5pt];
\coordinate (Q) at ({(1/2)*8/3},{(1/2)*16/3});
\draw[fill] (Q) circle [radius=1.5pt];
\coordinate (R) at ({(1/2)*4/3},{(1/2)*(-10/3)});
\draw[fill] (R) circle [radius=1.5pt];


%Point P is labeled.
\path let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0, font=\footnotesize] at ($(P)!0.15cm!90:(Q)$){\textit{P}};


%The intersection of the two lines is labeled T, and "pins" are drawn to Q and R.
\coordinate (T) at ({(1/2)*14/3},{(1/2)*10/3});
%
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (Q) -- ($(Q)!0.5cm!90:(T)$);
\path let \p1=($(Q)-(T)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0, font=\footnotesize] at ($(Q)!0.5cm!90:(T)$){\textit{Q}};
%
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (R) -- ($(R)!0.5cm!-90:(T)$);
\path let \p1=($(R)-(T)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+90}, inner sep=0, font=\footnotesize] at ($(R)!0.5cm!-90:(T)$){\textit{R}};


%The dashed line segment QR is drawn.
\draw[dashed] ({(1/2)*4/3},{(1/2)*(-10/3)}) -- ({(1/2)*8/3},{(1/2)*16/3});


%The axes are drawn.
\draw[latex-latex] ($(0,{(1/2)*(-9)})  +(0pt,-12.5pt)$) -- ($(0,{(1/2)*9})  +(0pt,12.5pt)$) node[above right]{$y$};
\draw[latex-latex] ($({(1/2)*(-3/2)},0) +(-12.5pt,0pt)$) -- ($({(1/2)*19/2},0) +(12.5pt,0pt)$) node[below right]{$x$};

\end{tikzpicture}

\end{document}

答案1

因为您已将shorten线条缩小了 1 毫米,但在放置节点时却没有考虑到这一点。

要么移除shorten >=1mm绘制引脚的地方,要么使用at ($(Q)!0.4cm!90:(T)$){\textit{Q}}(注意是 0.4 毫米而不是原来的 0.5 毫米),对于R节点也类似。

更多详情

那么让我们看看如果我们添加draw,very thinQ节点会发生什么R

在此处输入图片描述在此处输入图片描述

从引脚末端到节点边界的间隙是由 造成的shorten >=1mm,因此如果我们将其移除,我们将得到:

在此处输入图片描述在此处输入图片描述

节点边界内的空间可能是由字符本身的边界框引起的,因此与 TikZ 无关。如果您需要更少的空间,例如,可以使用负值来缩短,例如shorten >=-2pt,这将为您提供以下内容:

在此处输入图片描述在此处输入图片描述

完整代码:

\documentclass[10pt]{amsart}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}


\begin{document}
\begin{tikzpicture}

%The slope-intercept form for the line k is y = 2x - 6, and the slope-intercept form for
%the line $\ell$ is y = -x + 8. The two lines intersect at (8/3, 16/3). Point Q = (4/3, -10/3)
%is on line k, and point R = (8/3, 16/3) is on line $\ell$. (The diagram is magnified by 1/2.)
\draw[<->] ({(1/2)*(-3/2)},{(1/2)*(-9)}) -- ({(1/2)*15/2},{(1/2)*9});
\node[anchor=south west, inner sep=0, font=\footnotesize] at ($({(1/2)*15/2},{(1/2)*9}) +({atan(2)}:0.15)$){$\ell$};
\draw[<->] ({(1/2)*(-1)},{(1/2)*9}) -- ({(1/2)*19/2},{(1/2)*(-3/2)});
\node[anchor=north west, inner sep=0, font=\footnotesize] at ($({(1/2)*19/2},{(1/2)*(-3/2)}) +({atan(-1)}:0.15)$){\textit{k}};


%P, Q, and R are collinear. P is the midpoint of QR, Q is a point on $\ell$, and
%R is a point on k.
\coordinate (P) at ({(1/2)*2},{(1/2)*1});
\draw[fill] (P) circle [radius=1.5pt];
\coordinate (Q) at ({(1/2)*8/3},{(1/2)*16/3});
\draw[fill] (Q) circle [radius=1.5pt];
\coordinate (R) at ({(1/2)*4/3},{(1/2)*(-10/3)});
\draw[fill] (R) circle [radius=1.5pt];


%Point P is labeled.
\path let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0, font=\footnotesize] at ($(P)!0.15cm!90:(Q)$){\textit{P}};


%The intersection of the two lines is labeled T, and "pins" are drawn to Q and R.
\coordinate (T) at ({(1/2)*14/3},{(1/2)*10/3});
%
\draw[draw=gray, shorten <=1mm, shorten >=-2pt] (Q) -- ($(Q)!0.5cm!90:(T)$);
\path let \p1=($(Q)-(T)$), \n1={atan(\y1/\x1)} in node[%draw,very thin, % uncomment to get border of node
anchor={\n1-90}, inner sep=0, font=\footnotesize] at ($(Q)!0.5cm!90:(T)$){\textit{Q}};
%
\draw[draw=gray, shorten <=1mm, shorten >=-2pt] (R) -- ($(R)!0.5cm!-90:(T)$);
\path let \p1=($(R)-(T)$), \n1={atan(\y1/\x1)} in node[%draw,very thin, % uncomment to get border of node
anchor={\n1+90}, inner sep=0, font=\footnotesize] at ($(R)!0.5cm!-90:(T)$){\textit{R}};


%The dashed line segment QR is drawn.
\draw[dashed] ({(1/2)*4/3},{(1/2)*(-10/3)}) -- ({(1/2)*8/3},{(1/2)*16/3});


%The axes are drawn.
\draw[latex-latex] ($(0,{(1/2)*(-9)})  +(0pt,-12.5pt)$) -- ($(0,{(1/2)*9})  +(0pt,12.5pt)$) node[above right]{$y$};
\draw[latex-latex] ($({(1/2)*(-3/2)},0) +(-12.5pt,0pt)$) -- ($({(1/2)*19/2},0) +(12.5pt,0pt)$) node[below right]{$x$};

\end{tikzpicture}

\end{document}

相关内容