세그먼트 라벨링 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}

관련 정보