在 tikzpicture 上排版标题(版本 3)

在 tikzpicture 上排版标题(版本 3)

我想在两个相似的直角三角形的显示屏上放置一个标题。我在这里提供了很多代码,但只需查看最后一个命令即可。我使用current bounding box.south指示TikZ在显示屏底部排版标题。(这是节点命令的选项吗?)我yshift=-3mm在选项中指定。在我看来,由于标题排版在两行上,因此这两行的中间排版在显示屏的下边框下方。因此,标题的顶部会干扰显示。如何让包含标题的(不可见)框的顶部边缘位于显示屏下方 3 毫米处?

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

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


\begin{document}


\begin{tikzpicture}

%Rays k and $\ell$ have a common endpoint at the origin, which is labeled O. With respect to
%the horizontal line through O, k is inclined at an angle of 50 degrees, and $\ell$ is
%inclined at an angle of 15 degrees. To place the label for O, the rays are extended 15pt by an
%invisible path command "before" O. The endpoints of these extensions are called "label_O_below"
%and "label_O_above" and the midpoint of the line segment between label_O_below and label_O_above
%is called "label_O".  A node command typesets "O" at the point 7.5pt from O on the invisible
%line segment between O and label_O .
\draw[fill] coordinate (O) circle (1.5pt);

\coordinate (label_O_below) at (-130:15pt);
\coordinate (label_O_above) at (-165:15pt);
\coordinate (label_O) at ($(label_O_below)!0.5!(label_O_above)$);
\node[blue] at ($(O)!7.5pt!(label_O)$){$O$};

%Q_ray_k is a point on ray k and P_ray_ell is a point on $\ell$.
\draw[name path=ray_k, -latex,] (O) -- (50:7) coordinate (Q_ray_k);
\node (label_ray_k) at ($(Q_ray_k) + (50:7pt)$){$k$};
\draw[name path=ray_ell, -latex,] (O) -- (15:5.5) coordinate (P_ray_ell);
\node (label_ray_ell) at ($(P_ray_ell) + (15:6pt)$){$\ell$};

%This command labels a point "Q" 3.75cm from O on ray $k$.
\draw (O) -- (50:{15/4}) coordinate (Q);

%These commands label the projection of OQ onto \ell "P."  A line segment is drawn between
%Q and P, and a right-angle mark is placed at P.
\draw[name path=line_segment_QP] (Q) -- ($(O)!(Q)!(P_ray_ell)$) coordinate (P);

%These commands draw two angles - a right angle and an angle at O labeled $\theta$.
\draw pic[draw, angle radius=5mm,"$\theta$",angle eccentricity=1.5] {angle = P--O--Q};

\draw ($(P)!3mm!-45:(O)$) coordinate (U) -- ($(P)!(U)!(O)$);
\draw (U) -- ($(P)!(U)!(Q)$);


%These commands draw an invisible line segment perpendicular to ray k from Q to
%ray $\ell$. The intersection is labeled P'.
\path[name path=perpendicular_line_segment_from_Q] (Q) -- ($(Q)!3.5cm!90:(O)$);
\coordinate[name intersections={of=perpendicular_line_segment_from_Q and ray_ell, by={P'}}];

%These commands draw an invisible line segment perpendicular to ray \ell from P' to ray k.
%The intersection is labeled Q'.
\path[name path=perpendicular_line_segment_from_P'] (P') -- ($(P')!4cm!90:(P_ray_ell)$);
\coordinate[name intersections={of=perpendicular_line_segment_from_P' and ray_k, by={Q'}}];
\draw (P') -- (Q');

%These commands draw a right-angle mark at P^{\prime}.
\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\myshiftone" is issued to the node commands that position "$Q^{\prime}$" and "$P^{\prime}$."
\newlength\myshiftone
\settowidth{\myshiftone}{$^{\prime}$}


%These commands put the label "x" below line segment OP.  An invisible line segment is drawn
%2mm below OP, and "x" is typeset halfway along this invisible line segment.
\coordinate (O_shift_down_for_x) at ($(O)!2mm!-90:(P)$);
\coordinate (P_shift_down_for_x) at ($(P)!2mm!90:(O)$);
\node at ($(O_shift_down_for_x)!0.5!(P_shift_down_for_x)$){$x$};

%These commands put the label "r" above line segment OQ.  An invisible line segment is drawn
%2mm above OQ, and "r" is typeset halfway along this invisible line segment.
\coordinate (O_shift_up_for_r) at ($(O)!2mm!90:(Q)$);
\coordinate (Q_shift_up_for_r) at ($(Q)!2mm!-90:(O)$);
\node at ($(O_shift_up_for_r)!0.5!(Q_shift_up_for_r)$){$r$};


%These commands put a brace below line segment OP' and label the length `$x'$`.  This brace
%needs to be shifted downward from OP' to avoid interference with the labels O, P, and P'.
%First, coordinates for O_shift and P'_shift are defined to be 5mm from OP'.  A brace
%is drawn between O_shift and P'_shift.
\draw[decorate,decoration={brace,raise=5pt,amplitude=5pt,mirror}]
($(O)!5.5mm!-90:(P')$) coordinate (O_shift) -- ($(P')!5.5mm!90:(O)$) coordinate (P'_shift);
\coordinate (O_shift) at ($(O)!12mm!-90:(P')$);
\coordinate (P'_shift) at ($(P')!12mm!90:(O)$);
\node[xshift=0.5\myshiftone] at ($(O_shift)!0.5!(P'_shift)$){$x^{\prime}$};


%These commands put a brace above line segment OQ' and label the length `$r^{\prime}$`.  This brace
%needs to be shifted upward from OQ' to avoid interference with the labels O, Q, and Q'.
%First, coordinates for O_shift_up and P'_shift_up are defined to be 5mm from OQ'. A brace is drawn
%between O_shift_up and P'_shift_up.
\coordinate (O_shift_up) at ($(O)!5.5mm!90:(Q')$);
\coordinate (Q'_shift_up) at ($(Q')!5.5mm!-90:(O)$);
\draw[decorate,decoration={brace,raise=5pt,amplitude=5pt}] (O_shift_up) -- (Q'_shift_up);
\coordinate (O_shift_up_for_label_r') at ($(O)!12mm!90:(Q')$);
\coordinate (Q'_shift_up_for_label_r') at ($(Q')!12mm!-90:(O)$);
\node at ($(O_shift_up_for_label_r')!0.5!(Q'_shift_up_for_label_r')$){$r^{\prime}$};



%These commands draw an invisible line segment 3mm above OQ' for labels Q and Q'.
\coordinate (O_shift_for_labels_version_r') at ($(O)!3mm!90:(Q')$);
\coordinate (Q'_shift_for_labels_version_r') at ($(Q')!3mm!-90:(O)$);
\coordinate (Q'_shift_for_labels_extension) at ($(Q'_shift_for_labels_version_r')!-0.25cm!(O_shift_for_labels_version_r')$);
\path[name path=path_for_labels_Q_and_Q'] (O_shift_for_labels_version_r') -- (Q'_shift_for_labels_extension);
\path[name path=path_from_P_to_Q_above] (P) -- ($(Q)!-0.75cm!(P)$) coordinate (Q_above);
\path[name path=path_from_P'_to_Q'_above] (P') -- ($(Q')!-0.75cm!(P')$) coordinate (Q'_above);
\coordinate[name intersections={of=path_for_labels_Q_and_Q' and path_from_P_to_Q_above, by={Q_label}}];
\coordinate[name intersections={of=path_for_labels_Q_and_Q' and path_from_P'_to_Q'_above, by={Q'_label}}];
\node[green] at (Q_label){$Q$};
\node[blue, xshift=0.5\myshiftone] at (Q'_label){$Q^{\prime}$};
\node[red] at (Q'_label){$Q$};

%These commands draw an invisible line segment 2.5mm below OP' for labels P and P'. The center of the node
%containing $P'$ is displaced upwards by the subscript "1" in  $P'$. To avoid this upward vertical
%displacement, a \smash command is issued.
\coordinate (O_shift_for_labels_version_2) at ($(O)!2.5mm!-90:(P')$);
\coordinate (P'_shift_for_labels) at ($(P')!2.5mm!90:(O)$);
\path[name path=path_for_labels_P_and_P'] (O_shift_for_labels_version_2) -- (P'_shift_for_labels);
\path[name path=path_from_Q_to_P_below] (Q) -- ($(P)!-0.75cm!(Q)$) coordinate (P_below);
\path[name path=path_from_Q'_to_P'_below] (Q') -- ($(P')!-0.75cm!(Q')$) coordinate (P'_below);
\coordinate[name intersections={of=path_for_labels_P_and_P' and path_from_Q_to_P_below, by={P_label}}];
\coordinate[name intersections={of=path_for_labels_P_and_P' and path_from_Q'_to_P'_below, by={P'_label}}];
\node[green] at (P_label){$P$};
\node[blue, xshift=0.5\myshiftone] at (P'_label){$P\smash{^{\prime}}$};
\node[red] at (P'_label){$P$};


%These commands place y and y' halfway along line segments QP and Q'P'.
\path (O) -- ($(Q')!0.5!(P')$);
\coordinate (endpoint_for_line_segment_containing_labels_for_y_and_y') at ($($(Q')!0.5!(P')$)! -0.75cm! (O)$);
\path[name path=labels_for_y_and_y'_on_this_line] (O) -- (endpoint_for_line_segment_containing_labels_for_y_and_y');

\coordinate[name intersections={of=line_segment_QP and labels_for_y_and_y'_on_this_line, by={intersection_for_label_for_y}}];
\coordinate (label_for_y) at ($(intersection_for_label_for_y)! -2.5mm! (O)$);
\node[green] at (label_for_y){$y$};

\coordinate[name intersections={of=perpendicular_line_segment_from_P' and labels_for_y_and_y'_on_this_line, by={intersection_for_label_for_y'}}];
\coordinate (label_for_y') at ($(intersection_for_label_for_y')! -2.5mm! (O)$);
\node[blue, xshift=0.5\myshiftone] at (label_for_y'){$y\smash{^{\prime}}$};


\node[align=center,font=\bfseries, 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}

相关内容