忽略 TikZ 图中“素数”所占的空间

忽略 TikZ 图中“素数”所占的空间

我有两个直角三角形的图 - 一个内接于另一个。我有yy'表示其中一个锐角对边的长度。(表示y较小的三角形。)我还画了一条绿线,它是这个锐角的角平分线。我想让两个y在绿线上处于相同的相对位置。我尝试使用命令

\newlength\widthofprime

\settowidth{\widthofprime}{${}^{\prime}$}

\newlength\heightofprime

\settoheight{\heightofprime}{${}^{\prime}$}

以补偿素数占用的空间。我希望获得帮助来修改此代码以获得我想要的显示效果。

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}


\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}

%$\triangle{POQ}$ is a right triangle with it right angle at P, $\triangle{P'OQ'}$ is
%a right triangle with its right angle at P', and $\triangle{POQ}$ is inscribed in
%$\triangle{P'OQ'}$.
\coordinate (O) at (0,0);
\node[anchor={0.5*(15+50)}, inner sep=0] at ($(O) +({0.5*(195+230)}:0.15)$){$O$};
\coordinate (Q) at (50:{15/4});
\node[anchor={50-90}, inner sep=0] at ($(Q) +({50+90}:0.15)$){$Q$};
\coordinate (P) at ($(O)!(Q)!(15:1)$);
\node[anchor={15+90}, inner sep=0] at ($(P) +({15-90}:0.15)$){$P$};



%A right-angle mark is drawn at P.
\draw ($(P)!3mm!-45:(O)$) coordinate (U) -- ($(P)!(U)!(O)$);
\draw (U) -- ($(P)!(U)!(Q)$);


%P' is the intersection of ray{OP} and the line through Q that is perpendicular
%to ray{OQ}.
\path[name path=ray_on_which_points_P_and_P'_lie] (O) -- (15:4.75);
\path[name path=perpendicular_line_segment_from_Q] (Q) -- ($(Q)!2.75cm!90:(O)$);
\coordinate[name intersections={of=perpendicular_line_segment_from_Q and ray_on_which_points_P_and_P'_lie, by=P'}];
\node[anchor={15+90}, inner sep=0] at ($(P') +({15-90}:0.15)$){$P^{\prime}$};

%Q' is the intersection of ray{OQ} and the line through P' that is perpendicular
%to ray{OP}.
\path[name path=ray_on_which_points_Q_and_Q'_lie] (O) -- (50:5.75);
\path[name path=perpendicular_line_segment_from_P'] (P') -- ($(P')!3.25cm!-90:(O)$);
\coordinate[name intersections={of=perpendicular_line_segment_from_P' and ray_on_which_points_Q_and_Q'_lie, by=Q'}];
\node[anchor={50-90}, inner sep=0] at ($(Q') +({50+90}:0.15)$){$Q'$};

%The sides of the triangle are drawn.
\draw (O) -- (P');
\draw (O) -- (Q');
\draw (P) -- (Q);
\draw (P') -- (Q');


%A right-angle mark is drawn at P'.
\draw ($(P')!3mm!-45:(O)$) coordinate (U') -- ($(P')!(U')!(O)$);
\draw (U') -- ($(P')!(U')!(Q')$);



%The superscript "^{\prime}" in "$Q^{\prime}$" and "$P^{\prime}$" displaces the "Q" in "$Q^{\prime}$" and the
%"P" in "$P^{\prime}$" leftward artificially by half of its width.  To cancel this artificial shift, a
%"\newlength" command is defined as the width of the subscript "^{\prime}," and the command
%"xshift=0.5\widthofprime" is issued to the node commands that position "$Q^{\prime}$" and "$P^{\prime}$."
\newlength\widthofprime
\settowidth{\widthofprime}{${}^{\prime}$}
\newlength\heightofprime
\settoheight{\heightofprime}{${}^{\prime}$}


%The length of PQ is labeled y.
\draw let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0] at ($($(P)!0.15cm!-90:(Q)$)! 0.5! ($(Q)!0.15cm!90:(P)$)$){$y$};

%The length of P'Q' is labeled y'.
\draw let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)} in node[xshift={cos(\n1)*(0.5\widthofprime)}, yshift={sin(\n1+180)*(0.5\heightofprime)}, anchor={\n1-90}, inner sep=0] at ($($(P')!0.15cm!-90:(Q')$)! 0.5! ($(Q')!0.15cm!90:(P')$)$){$y^{\prime}$};


\draw[green] (O) -- ({0.5*(15+50)}:6);

\node[align=center,font=\bfseries,anchor=north,yshift=-3mm] at (current bounding box.south) {An illustration of similar right triangles \\ $\mathbf{\triangle{POQ}}$ and $\mathbf{\triangle{P^{\prime}OQ^{\prime}}}$};


\end{tikzpicture}


\end{document}

答案1

在我看来,您发布的大部分代码与您试图实现的最终目标完全无关。是的,我确信可以通过在尝试时移动节点来隐藏素数,但为什么要让事情变得比需要的更复杂呢?

建议的代码egreg 的评论可以整齐地包装在宏中:

% a macro for the prime taking no space; rename this to whatever you like
\newcommand{\ghostprime}{\makebox[0pt][l]{$\smash{'}$}}

您可以将此宏的名称更改为您选择的任何名称。\ghostprime然后,您可以在通常使用宏的任何上下文中使用宏',只有这个宏不会占用任何空间。它独立于任何 TiZ 库或计算,但您可以将其用作任何节点文本的一部分,如果您不希望素数影响节点的大小或定位。

这是一份完整的文档,显示了与标准素数相比的使用情况。方框只是为了表明它\ghostprime确实不占用空间。

\documentclass{article}

% a macro for the prime taking no space; rename this to whatever you like
\newcommand{\ghostprime}{\makebox[0pt][l]{$\smash{'}$}}

% just a few things for testing in the example
\fboxsep 0pt
\newcommand{\tr}[2]{#1 & \fbox{$#2$}}

\begin{document}
\begin{tabular}{lc}
\tr{Plain}{x} \\
\tr{`Ghost' Prime}{x\ghostprime} \\
\tr{Standard Prime}{x'}
\end{tabular}
\end{document}

在此处输入图片描述

答案2

以下代码仅显示两个相似直角三角形,其长度yy'以及角平分线用绿色表示。y现在,两个相对于绿线的位置一致。

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}


\begin{document}

\begin{tikzpicture}

%$\triangle{POQ}$ is a right triangle with it right angle at P, $\triangle{P'OQ'}$ is
%a right triangle with its right angle at P', and $\triangle{POQ}$ is inscribed in
%$\triangle{P'OQ'}$.
\coordinate (O) at (0,0);

\coordinate (Q) at (50:{15/4});
\coordinate (P) at ($(O)!(Q)!(15:1)$);



%P' is the intersection of ray{OP} and the line through Q that is perpendicular
%to ray{OQ}.
\path[name path=ray_on_which_points_P_and_P'_lie] (O) -- (15:4.75);
\path[name path=perpendicular_line_segment_from_Q] (Q) -- ($(Q)!2.75cm!90:(O)$);
\coordinate[name intersections={of=perpendicular_line_segment_from_Q and ray_on_which_points_P_and_P'_lie, by=P'}];

%Q' is the intersection of ray{OQ} and the line through P' that is perpendicular
%to ray{OP}.
\path[name path=ray_on_which_points_Q_and_Q'_lie] (O) -- (50:5.75);
\path[name path=perpendicular_line_segment_from_P'] (P') -- ($(P')!3.25cm!-90:(O)$);
\coordinate[name intersections={of=perpendicular_line_segment_from_P' and ray_on_which_points_Q_and_Q'_lie, by=Q'}];

%The sides of the triangle are drawn.
\draw (O) -- (P');
\draw (O) -- (Q');
\draw (P) -- (Q);
\draw (P') -- (Q');


%The length of line segment PQ is labeled y.
\path[name path=a_path_on_which_label_for_y] ($(P)!0.15cm!-90:(Q)$) -- ($(Q)!0.15cm!90:(P)$);
\path[name path=another_path_on_which_label_for_y] (O) -- ({0.5*(15+50)}:5);
\coordinate[name intersections={of=a_path_on_which_label_for_y and another_path_on_which_label_for_y, by=label_for_y}];
\draw let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0] at (label_for_y){$y$};

%The length of line segment P'Q' is labeled y'.
\path[name path=a_path_on_which_label_for_y'] ($(P')!0.15cm!-90:(Q')$) -- ($(Q')!0.15cm!90:(P')$);
\path[name path=another_path_on_which_label_for_y'] (O) -- ({0.5*(15+50)}:5);
\coordinate[name intersections={of=a_path_on_which_label_for_y' and another_path_on_which_label_for_y', by=label_for_y'}];
\draw let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0] at (label_for_y'){$y{\makebox[0pt][l]{\smash{${}^{\prime}$}}}$};

\draw[green] (O) -- ({0.5*(15+50)}:6);


\end{tikzpicture}

\end{document}

相关内容