如何将长度和直角添加到三角形中

如何将长度和直角添加到三角形中

下面创建一个三角形。

Q1. 如何为每边添加长度,例如 5cm、6cm 和 xcm。

Q2. 如何在 A 上添加直角符号?

 \item[b)]
      \begin{tikzpicture}
% Draw the triangle
        \draw[fill=gray!10]  (0, 0) coordinate (A) 
        -- (0,5) coordinate (C) 
        -- (6,0) coordinate (B) 
        -- (0, 0);

% Draw nodes
        \node at (A)[anchor=north] {A};
        \node at (B)[anchor=north] {B};
        \node at (C)[anchor=south] {C};
      \end{tikzpicture}

在此处输入图片描述

答案1

一种选择:

\documentclass{article}
\usepackage{tikz}

\begin{document}

      \begin{tikzpicture}
% Draw the triangle
        \draw[fill=gray!10]  (0, 0) coordinate (A) 
        -- node[left] {$3$\,cm} (0,5) coordinate (C) 
        -- node[above right] {$5$\,cm} (6,0) coordinate (B) 
        -- node[below] {$4$\,cm}  (0, 0);
       \draw (0,10pt) -- ++(10pt,0) -- ++(0,-10pt);
% Draw nodes
        \node at (A)[anchor=north] {$A$};
        \node at (B)[anchor=north] {$B$};
        \node at (C)[anchor=south] {$C$};
      \end{tikzpicture}

\end{document}

在此处输入图片描述

使用brace装饰器,您可以在侧面添加括号来指示长度:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

      \begin{tikzpicture}
% Draw the triangle
        \draw[fill=gray!10]  (0, 0) coordinate (A) 
        -- (0,5) coordinate (C) 
        -- (6,0) coordinate (B) 
        -- (0, 0);
       \draw[decoration={brace,mirror,raise=2pt},decorate] 
         (A) -- node[below=4pt] {$4$\,cm} (B); 
       \draw[decoration={brace,mirror,raise=2pt},decorate] 
         (B) -- node[above=4pt,sloped] {$5$\,cm} (C); 
       \draw[decoration={brace,mirror,raise=2pt},decorate] 
         (C) -- node[left=4pt] {$3$\,cm} (A); 

       \draw (0,10pt) -- ++(10pt,0) -- ++(0,-10pt);
% Draw nodes
        \node at (A)[anchor=north] {$A$};
        \node at (B)[anchor=north] {$B$};
        \node at (C)[anchor=south] {$C$};
      \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容