下面创建一个三角形。
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}