2

I have a triangle and one of its altitudes drawn. The length of the altitude is labeled "h." I use the rotate option in the node command to try to get the letter parallel to the altitude. The rotation is not right, though.

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

This MWE gives: enter image description here

  • 1
    I complete your code that it can be compiled now. Also I add Image which your MWE produced. As far as I can see, h is parallel to triangle altitude. How you expect to be oriented? – Zarko Jul 12 '16 at 18:30
6

Your code is unnecessarily complicated, why make two commands, one for the line and one for the node (which is very complicated anyways), when you can do all in one?

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

That's how I'd add the h to the line. sloped positions it 90° respective to the path, then you just rotate it back 90° degrees.

But speaking about your question: the letter is actually properly positioned. It doesn't look parallel because it's being typeset in math mode, with italics. See what happens when you draw the node:

enter image description here

  • Thanks for the explanation. The font being italics gives the appearance of the "h" being rotated too much. – Adelyn Jul 13 '16 at 0:37
  • @Adelyn You're welcome! :) Hope you didn't mind me criticizing your code. It's not wrong, but I think it's usually easier to have a shorter code, with more simple commands. It makes it easier for you to review it, for example. :D I'm glad I was able to help. – Alenanno Jul 13 '16 at 18:12
1

To my opinion the rotating label h is against rule of labeling other triangle edges (there are label perpendicular to line). Also I seconded to @Alenanno statement, that your code is unnecessary complex. So, the contribution of this answer is to show, how to simplify code for your sketch. In this I employ TikZ libraries: angles and quotes, which are already loaded in MWE but not used:

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

This MWE gives:

enter image description here

Edit: if you insist to rotate h, then you use Alenanno solution, which slightly modified is:

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

and gives:

enter image description here

Interestingly, rotation of path label gives on the first sight strange result: node is very displaced from path. This is one of consequences, that path labels are designed to be horizontally aligned right or left from path or aligned with path and placed above or below it. With other words, to these options different align of path's labels is by design considered as least unusual if not wrong. In engineering the path labels is always aligned with paths.

Of course, in spirit of your question the mine answer is off-topic, however it is worth to consider it in your future sketch designs.

  • I wanted to be sure that I was using the rotate option correctly. Alenanno explained to me that I was using it correctly and that the font selection gave only the appearance that I was not using it correctly. – Adelyn Jul 13 '16 at 0:40
  • You are welcome. Any way I slightly improve my edit of answer. – Zarko Jul 13 '16 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.