1

I am trying to draw the height line in Tikz. It should go from B and right down to the lower part of the triangle. But that isn't happening with the following MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}

\begin{document}

\begin{tikzpicture}[scale=1.25]%,cap=round,>=latex]
   \coordinate [label=left:$A$] (A) at (-2cm,-1.cm);
   \coordinate [label=right:$C$] (C) at (2.2cm,-1.0cm);
   \coordinate [label=above:$B$] (B) at (1cm,1.0cm);
   \draw (A) -- node[sloped,above] {c} (B) -- node[sloped,above,] {a} (C) -- node[below] {b} (A);
   \draw[dashed] (B) -- (b) ;
\end{tikzpicture}

\end{document}

enter image description here

  • You can use let to do this: \draw[dashed] let \p1 = (B) in (B) -- (\x1, -1cm) ;. – OSjerick Nov 10 '15 at 14:07
1

When line A--C is horizontal, like in this case, command

\draw[dashed] (B) -- (B|-A); 

will also draw triangle height without loading calc library.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}

\begin{document}

\begin{tikzpicture}[scale=1.25]%,cap=round,>=latex]
\coordinate [label=left:$A$] (A) at (-2cm,-1.cm);
\coordinate [label=right:$C$] (C) at (2.2cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1cm,1.0cm);
\draw (A) -- node[sloped,above] {c} (B) -- node[sloped,above,] {a} (C) -- node[below] {b} (A);
\draw[dashed] (B) -- (A-|B) ;

\end{tikzpicture}

\end{document}

enter image description here

3

Here a MWE using the calc-library for drawing the perpendicular on the b-edge.

For the dashed line (A)!(B)!(C) means: project point B on the line AC. For the dotted line you need to give the node with label b a name.

\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}
    \coordinate [label=left:$A$] (A) at (-2, -1);
    \coordinate [label=above:$B$] (B) at (1, 1);
    \coordinate [label=right:$C$] (C) at (2.2, -1);
    \draw (A) -- node [sloped, above] (c) {c} (B) -- node [sloped, above] (a) {a} (C) -- node [below] (b) {b} cycle;        
    \draw [dashed] (B) -- ($(A)!(B)!(C)$);
    \draw [dotted] (B) -- (b);
  \end{tikzpicture}
\end{document}

rendered image

0

Note the error that says no shape b is known.

Your node with the text b has no name, i.e. it is made with node[below]{node text} rather than node[below](node name) {node text}.

If you want a line down to the b, make it into node[below](b){b}, but that is not a normal. To get a normal you can do \draw (B) -- (B|-A);, where B|-A is the point with the x-coordinate of B and the y-coordinate of A.

enter image description here

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.25]%,cap=round,>=latex]
\coordinate [label=left:$A$] (A) at (-2cm,-1.cm);
\coordinate [label=right:$C$] (C) at (2.2cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1cm,1.0cm);
\draw (A) -- node[sloped,above] {c} (B) -- node[sloped,above,] {a} (C) -- node[below] (b) {b} (A);
\draw[dashed] (B) -- (b) ;
\draw[blue,dashed] (B) -- (B|-A) ;
\end{tikzpicture}
\end{document}

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.