# Ignoring the space occupied by "a prime" in a TikZ diagram

I have a diagram of two right triangles - one inscribed in another. I have y and y' indicating the length of the leg opposite one of the acute angles. (The y is for the smaller triangle.) I also have a green line drawn that is the angle bisector of this acute angle. I want to get the two y's in the same relative position on the green line. I tried using the commands

\newlength\widthofprime

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

\newlength\heightofprime

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


to compensate for the space occupied by the prime. I would like to get help modifying this code to get the display that I want.

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

• $P\makebox[0pt][l]{\smash{$'$}}$ will produce a prime that occupies no space. May 2 '16 at 22:34
• @egreg I just tried I had {$y^{\makebox[0pt][l]{\smash{${\prime}$}}}$}. That types the ' in the "regular" font and not as a superscript. The y in y' is now above the green line. May 2 '16 at 22:43
• ... but not in any of the ways suggested so far? What are the criteria then for acceptable modifications if those suggested are unacceptable?
– cfr
May 3 '16 at 3:25
• @cfr I now understand that use of the \smash command is appropriate. Why is the y in y' almost above the green line but the other y is "in the middle" of the green line? May 3 '16 at 13:39
• It is rather difficult to say since you have a great deal of irrelevant code and so it is difficult to know how you implemented the suggestion. If you simplified the code to what's really essential, the problem would be easier to understand.
– cfr
May 3 '16 at 15:56

Most of the code you have posted is, IMHO, completely unrelated to the end goal you are trying to achieve. Yes, I'm sure it is possible to hide the prime by shifting nodes as you are attempting, but why make things more complicated than they need to be?

The code proposed in egreg's comment can be neatly wrapped in a macro:

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


You can change this macro's name to anything of your choosing. The \ghostprime macro can then be used in any context where you would normally use the ' character for a prime, only this one will take up no space. It is independent of any TikZ libraries or calculations, but you can use it as part of any node text where you do not want the prime to influence the size or positioning of the node.

Here's a complete document showing the usage compared to a standard prime. The boxes are just to show that \ghostprime does indeed take up no space.

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


• With your code, the y in y' is typeset above the green line but the other y is typeset on the green line - the green line goes through the middle of the y. That is what I want for the y in y'. May 3 '16 at 14:34
• @Adelyn for your first question, please see What is the advantage of using $f^\prime$ instead of $f'$?. My code does not produce a green line, so I'm not sure what you speak of there. May 3 '16 at 16:05
• Compile the code in my post for the second question. May 3 '16 at 16:39
• @Adelyn the y and y' nodes are positioned precisely where you specified them to be... I'm not sure what else there is to say. If you want them to be positioned the same relative to the green line, you have to account for the projection of the 0.15cm offset line—it is effectively another similar triangle. Right now you are simply offsetting the side of the existing right triangle, which has a shorter length than a projected offset line. May 3 '16 at 17:47

Here is code that just shows the two similar right triangles and the lengths y and y', and the angle bisector, drawn green. The two y's are now positioned consistently with respect to the green line.

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