我正在尝试在 Tikz 中绘制高度线。它应该从 B 一直延伸到三角形的下部。但以下 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}
答案1
当线A--C
是水平的,就像在这种情况下,命令
\draw[dashed] (B) -- (B|-A);
无需加载库也能绘制三角形高度calc
。
\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}
答案2
这里,MWE 使用calc
库来绘制边上的垂直线b
。
对于虚线来说,(A)!(B)!(C)
意思是:将点投影B
到线上AC
。对于点线,你需要给带标签的节点b
命名。
\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}
答案3
请注意指出的错误no shape b is known
。
带有文本的节点b
没有名称,即它是由node[below]{node text}
而不是组成的node[below](node name) {node text}
。
如果您想要一条直线到b
,请将其变成node[below](b){b}
,但这不是正常的。要获得正常值,您可以执行\draw (B) -- (B|-A);
,其中B|-A
是 x 坐标为B
、y 坐标为 的点A
。
\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}