概念標籤 段標籤的長度 tikz

概念標籤 段標籤的長度 tikz

我剛剛讀到一個關於標記線段長度的問題,但這對我來說相當困難,因為之前所有的問題都使用角度來標記長度/距離,而我不理解這個概念。有人可以教我標記段長度的概念嗎?

我將給出我的實驗和一個需要在 TikZ 中描述的問題。

這是我嘗試過的程式碼:

\begin{tikzpicture}
\tikzset{
mydot/.style={
fill,
circle,
inner sep=1.5pt
}
}
\path (0:4.5) coordinate (A) (0:1.5) coordinate (B) (0:0) coordinate (C);
\draw (A)
-- (B) node [midway, above]{$x$} -- (C) node [midway, above]{$y$}  -- (A) -- cycle;
\node[mydot,label={below left:$A$}] at (A) {};
\node[mydot,label={below left:$B$}] at (B) {};
\node[mydot,label={below left:$C$}] at (C) {};
\draw[|<->|] ($(A)!5mm!90:(C)$)--node[fill=white] {$z$} ($(C)!5mm!0:(A)$);
\end{tikzpicture}

實際上,這段程式碼是我從過去發布的問題中複製的,但我在這裡為我的案例安排了它。

這是我想在 TikZ 中描述的問題的裁剪圖像

問題

順便說一句,我想讓該段水平。那麼謝謝。

答案1

像這樣的東西

在此輸入影像描述

\begin{tikzpicture}
\tikzset{
    mydot/.style={
        fill,
        circle,
        inner sep=1.5pt
    }
}
\coordinate  (A) at(0,0) ;
\coordinate  (B)  at (3,0);
\coordinate  (C) at (6,0);
\coordinate  (D) at (9,0);
% (3,0) coordinate (B) (6,0) coordinate (C) (9,0) coordinate (D);
\draw (A) -- node [midway, above]{\scriptsize $x=21-14$}
(B)  -- node [midway, above]{\scriptsize $y=13-x$}
(C)   -- 
(D);
\node[mydot,label={below left:$A$}] at (A) {};
\node[mydot,label={below left:$B$}] at (B) {};
\node[mydot,label={below left:$C$}] at (C) {};
\node[mydot,label={below left:$D$}] at (D) {};
\draw[|<->|,red,line width=1pt] ($(A)!10mm!-90:(C)$)--node[fill=white] {$13$} ($(C)!10mm!90:(A)$);
\draw[|<->|,blue,line width=1pt] ($(B)!15mm!-90:(D)$)--node[fill=white] {$14$} ($(D)!15mm!90:(B)$);
\draw[|<->|,green,line width=1pt] ($(A)!20mm!-90:(D)$)--node[fill=white] {$21$} ($(D)!20mm!90:(A)$);
\end{tikzpicture}

編輯--在片段上方新增標籤

在此輸入影像描述

\begin{tikzpicture}
\tikzset{
    mydot/.style={
        fill,
        circle,
        inner sep=1.5pt
    }
}
\coordinate  (A) at(0,0) ;
\coordinate  (B)  at (3,0);
\coordinate  (C) at (6,0);
\coordinate  (D) at (9,0);
% (3,0) coordinate (B) (6,0) coordinate (C) (9,0) coordinate (D);
\draw (A) -- node [midway, above]{\scriptsize $x=21-14$}
(B)  -- node [midway, above]{\scriptsize $y=13-x$}
(C)   -- 
(D);
\node[mydot,label={below left:$A$}] at (A) {};
\node[mydot,label={below left:$B$}] at (B) {};
\node[mydot,label={below left:$C$}] at (C) {};
\node[mydot,label={below left:$D$}] at (D) {};
\draw[|<->|,red,line width=1pt] ($(A)!10mm!90:(C)$)--node[fill=white] {$13$} ($(C)!10mm!-90:(A)$);
\draw[|<->|,blue,line width=1pt] ($(B)!15mm!90:(D)$)--node[fill=white] {$14$} ($(D)!15mm!-90:(B)$);
\draw[|<->|,green,line width=1pt] ($(A)!20mm!90:(D)$)--node[fill=white] {$21$} ($(D)!20mm!-90:(A)$);
\end{tikzpicture}

答案2

編輯: 考慮的是@jsbibra 的評論。

像這樣:

在此輸入影像描述

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}
\usepackage{amsmath}


\begin{document}
    \begin{tikzpicture}[x=7mm,
dot/.style = {circle, fill, inner sep=1.5pt,
              label=#1,
              node contents={}},
arr/.style = {{Bar[width=3mm].Straight Barb[]}-{Straight Barb[].Bar[width=3mm]},
              shorten >=-0.5\pgflinewidth, shorten <=-0.5\pgflinewidth,
              very thin},
every edge quotes/.style = {font=\small, auto=center}
                        ]
\node (a) [dot=${A=0}$];
\node (b) [dot=$B$, right= 7 of a];
\node (c) [dot=${C=13}$, right=13 of a];
\node (d) [dot=${D=21}$, right=21 of a];
%
\draw (a) to["${\begin{aligned}
                \overline{AB} & = \overline{AD}-\overline{BD}\\
                              & = 21-14=\color{red}7
                \end{aligned}}$"]   (b)
          to["${\begin{aligned}
                \overline{BC} & = \overline{AC}-\overline{AB}\\
                              & = 13-7=\color{red}6
                \end{aligned}}$"]   (c)   -- (d);
% aux coordinate and dimension BD
\coordinate[below=6mm of b] (b1);
\draw[arr]  (b1) to ["${\overline{BD} = 14}$" fill=white]  (b1-|d);
\end{tikzpicture}
\end{document}

相關內容