节点命令中的“rotate”选项未按指定方式旋转字母

节点命令中的“rotate”选项未按指定方式旋转字母

我画了一个三角形,并画出了它的一条高。高的长度标记为“h”。我使用rotate节点命令中的选项尝试使字母与高平行。但是旋转不正确。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\begin{document}
    \begin{tikzpicture}

\begin{document}
     \begin{tikzpicture}

%Two triangles illustrating the Law of Cosines is drawn.  The first has an acute angle at C,
%and the second has an obtuse triangle at C drawn.

%The first triangle is drawn.
\path (0,0) coordinate (A) (3.5,0) coordinate (B) (115:2) coordinate (C);
\draw (A) -- (B) -- (C) -- (A) -- cycle;

%Labels for the vertices are typeset.
\draw node[anchor=north, inner sep=0] at (0,-0.15){$A$};
\draw node[anchor=north, inner sep=0] at ($(B) +(0,-0.15)$){$B$};
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={0.5*(115+(\n1+180))-180}, inner sep=0] at ($(C) +({0.5*(115+(\n1+180))}:0.15)$){$C$};

%P is the foot of the altitude of $\triangle{ABC}$  from A.
\coordinate (P) at ($(B)!(A)!(C)$);
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0] at ($(P)!1.5mm!90:(B)$){$P$};
%
\draw[dashed] (P) -- (A);
%
%A right-angle mark is drawn at P.
\coordinate (U) at ($(P)!3mm!45:(A)$);
\draw (U) -- ($(P)!(U)!(A)$);
\draw (U) -- ($(P)!(U)!(B)$);

%The labels for the lengths of the sides of the triangle are typeset. (The label for the length of BC
%is typeset under an arrow.)
\draw[|<->|] ($(B)!0.6cm!-90:(C)$) -- ($(C)!0.6cm!90:(B)$);
\path let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+90}, inner sep=0, font=\footnotesize, rotate=\n1] at ($($(B)!0.5!(C)$) +({\n1+90}:0.8)$){$a$};
%
\path let \p1=($(A)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+90}, inner sep=0, font=\footnotesize] at ($($(A)!0.15cm!90:(C)$)!0.5!($(C)!0.15cm!-90:(A)$)$){$b$};
%
\path node[anchor=north, inner sep=0, font=\footnotesize] at ($($(A)!0.15cm!-90:(B)$)!0.5!($(B)!0.15cm!90:(A)$)$){$c$};
%

%The labels for the lengths h and x are typeset.
\path let \p1=($(A)-(P)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+90}, inner sep=0, font=\footnotesize, rotate={\n1-90}] at ($($(A)!0.5!(P)$)!1.5mm!-90:(P)$){$h$};
\path let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-90}, inner sep=0, font=\footnotesize, rotate=\n1] at ($($(C)!0.5!(P)$)!1.5mm!90:(P)$){$x$};

%The angle mark indicating the measure of $\angle{ACB}$ is drawn. The label $\theta$ for its measure
%is typeset.
\draw[draw=blue, line width=0.8pt] let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in ($(C) +(-65:0.35)$) arc (-65:\n1:0.35);
\path let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in coordinate (label_for_theta) at ($(C) +({0.5*(-65+\n1)}:0.4)$);
\path let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[blue, anchor={0.5*(-65+\n1)-180}, inner sep=0, font=\tiny] at (label_for_theta){$\theta$};

    \end{tikzpicture}
\end{document} 

该 MWE 给出: 在此处输入图片描述

答案1

您的代码不必要地复杂,为什么要创建两个命令,一个用于线路,一个用于节点(无论如何这非常复杂),而您可以用一个命令完成所有操作?

\draw[dashed] (P) -- (A) node[right, midway,font=\footnotesize,sloped, draw, rotate=-90] {$h$};

这就是我将其添加h到线的方法。sloped将其定位在相对于路径的 90° 位置,然后将其旋转回 90° 度。

但说到你的问题:这封信实际上位置正确。它看起来并不平行,因为它是在数学模式下排版的,并且带有斜体。看看绘制节点时会发生什么:

在此处输入图片描述

答案2

我认为旋转标签h违反了标记其他三角形边的规则(有垂直于线的标签)。我也赞同@Alenanno 的说法,你的代码没有必要那么复杂。所以,这个答案的贡献是展示如何简化你的草图代码。在这里我使用了 TikZ 库:anglesquotes,它们已经在 MWE 中加载但未使用:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{angles, calc, quotes}

\begin{document}
    \begin{tikzpicture}[
every label/.append style = {font=\small, inner sep=2pt},
             angle radius = 5mm,
          my angle/.style = {draw=blue, very thick,
                             angle eccentricity=1.3} % angle label position!
                        ]
% The first triangle is drawn.
\coordinate[label=below:$A$]  (A) at (0,0);
\coordinate[label=below:$B$]  (B) at (3.5,0);
\coordinate[label=above:$C$]  (C) at (115:2);

% P is the foot of the altitude of $\triangle{ABC}$  from A.
\coordinate[label=45:$P$] (P) at ($(B)!(A)!(C)$);
    \draw (A) to [sloped,"$c$" '] (B) -- (P) to [sloped,"$x$" '] (C) to [sloped,"$b$" '] (A);
    \draw[densely dashed] (P) to [pos=0.65, sloped, "$h$"] (A);
% length a
\draw[|<->|] ($(B)!7mm!-90:(C)$) to [pos=0.6,sloped,"$a$" '] ($(C)!7mm!90:(B)$);

% The angle mark indicating the measure of $\angle{ACB}$ is drawn. 
\pic [my angle, "$\theta$"] {angle = A--C--P};
% mark orthogonal 
\draw   ($(P)!2mm!0:(A)$)   coordinate (p')  --  
        ($(p')!2mm!90:(A)$) -- ($(P)!2mm!0:(B)$);
    \end{tikzpicture}
\end{document} 

该 MWE 给出:

在此处输入图片描述

编辑:如果你坚持要旋转h,那么你使用Alenanno解决方案,稍微修改一下:

\draw[densely dashed] (P) -- node [font=\small,sloped,right,rotate=-90] {$h$} (A); 

并给出:

在此处输入图片描述

有趣的是,路径标签的旋转乍一看会产生奇怪的结果:节点与路径的位移很大。这是路径标签设计为水平对齐路径右侧或左侧或与路径对齐并放置在其上方或下方的后果之一。换句话说,对于这些选项,路径标签的不同对齐方式是设计使然经过考虑的至少是不寻常的,如果不是错误的。在工程中路径标签总是与路径对齐。

当然,从你的问题来看,我的回答是题外话,但在你未来的草图设计中值得考虑它。

相关内容