yshift 不适用于由 'tkz-euclide' 定义的点
如何让它工作?
\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\tkzDefPoint(0,0){A}
\tkzDefPoint(2,0){B}
\tkzDrawSegment(A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below](A,B)
%not working
\begin{scope}[yshift=-1cm]
\draw [|<->|] (A) -- node[above]{2 cm} (B);
\end{scope}
%working
\begin{scope}[yshift=-1cm]
\draw [|<->|] (0,0) -- node[above]{2 cm} (2,0);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
现在我得到了一个解决方案....
\draw [|<->|,>=stealth] ([yshift=1cm]A) -- node[above]{2 cm} ([yshift=1cm]B);
\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\tkzDefPoint(0,0){A}
\tkzDefPoint(2,0){B}
\tkzDrawSegment(A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below](A,B)
%now working
\draw [|<->|,>=stealth] ([yshift=1cm]A) -- node[above]{2 cm} ([yshift=1cm]B);
%working
\begin{scope}[yshift=-1cm]
\draw [|<->|] (0,0) -- node[above]{2 cm} (2,0);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
使用 tkz-euclide 的解决方案
\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\tkzDefPoint(0,0){A}
\tkzDefPoint(2,0){B}
\tkzDrawSegment(A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below](A,B)
\tkzDrawSegment[|<->|]([yshift=-1cm]A,[yshift=-1cm]B)
\tkzLabelSegment[above]([yshift=-1cm]A,[yshift=-1cm]B){$2$ cm}
\end{tikzpicture}
\end{document}