我想画出如图所示的线段
我用过tkz-euclide
,我得到了这个
但我希望长度文本位于行之间,如第一张图所示。这是我的代码
\begin{figure}
\centering
\begin{tikzpicture}[vect/.style={<->,
shorten >=1pt,>=latex},vect1/.style={|<->|,
shorten >=1pt,>=latex},scale=1]
\tkzDefPoint(0,0){O}
\tkzDefPoint(9,0){Z}
\tkzDefPoint(1,0){A}
\tkzDefPoint(8,0){D}
\tkzDefPoint(2.3,0){B}
\tkzDefPoint(5,0){C}
\tkzDefPoint(1,0.5){A1}
\tkzDefPoint(8,0.5){D1}
\tkzDefPoint(1,-0.6){A2}
\tkzDefPoint(5,-0.6){C2}
\tkzDefPoint(2.3,-1.2){B2}
\tkzDefPoint(8,-1.2){D2}
\tkzDrawSegments[thick,vect](O,Z)
\tkzDrawPoints[color=blue](A,B,C,D)
\tkzLabelPoints[below](A,B,C,D)
\tkzDrawSegments[vect1](A1,D1 A2,C2 B2,D2)
\tkzLabelSegments[above](A1,D1){24 cm}
\tkzLabelSegments[below](A2,C2){15 cm}
\tkzLabelSegments[below](B2,D2){17 cm}
\end{tikzpicture}
\end{figure}
答案1
和TikZ
\documentclass[10pt]{article}
\usepackage{tkz-euclide}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[vect/.style={<->,
shorten >=1pt,>=latex},vect1/.style={|<->|,
shorten >=1pt,>=latex},scale=1]
\tkzDefPoint(0,0){O}
\tkzDefPoint(9,0){Z}
\tkzDefPoint(1,0){A}
\tkzDefPoint(8,0){D}
\tkzDefPoint(2.3,0){B}
\tkzDefPoint(5,0){C}
\tkzDefPoint(1,0.5){A1}
\tkzDefPoint(8,0.5){D1}
\tkzDefPoint(1,-0.6){A2}
\tkzDefPoint(5,-0.6){C2}
\tkzDefPoint(2.3,-1.2){B2}
\tkzDefPoint(8,-1.2){D2}
\tkzDrawSegments[thick,vect](O,Z)
\tkzDrawPoints[color=blue](A,B,C,D)
\tkzLabelPoints[below](A,B,C,D)
\tkzDrawSegments[vect1](A1,D1 A2,C2 B2,D2)
% \tkzLabelSegments[center](A1,D1){24 cm}
% \tkzLabelSegments[below](A2,C2){15 cm}
% \tkzLabelSegments[below](B2,D2){17 cm}
\path (A1) -- (D1) node[fill=white,midway]{24 cm};
\end{tikzpicture}
\end{figure}
\end{document}
附有tkz-euclide
文档第127和128页。
\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=2]
\pgfkeys{/pgf/number format/.cd,fixed,precision=2}
\tkzDefPoint(0,0){A}
\tkzDefPoint(3.07,0){B}
\tkzInterCC[R](A,2.37)(B,1.82)
\tkzGetPoints{C}{C'}
\tkzDrawCircle[in](A,B,C) \tkzGetPoint{G}
\tkzGetLength{rIn}
\tkzDrawPolygon(A,B,C)
\tkzDrawPoints(A,B,C)
\tkzCalcLength(A,B)\tkzGetLength{ABl}
\tkzCalcLength(B,C)\tkzGetLength{BCl}
\tkzCalcLength(A,C)\tkzGetLength{ACl}
\begin{scope}[dim style/.style={dashed,sloped,teal}]
\tkzDrawSegment[dim={\pgfmathprintnumber\BCl,6pt,
text=red}](C,B)
\tkzDrawSegment[dim={\pgfmathprintnumber\ACl,6pt,}](A,C)
\tkzDrawSegment[dim={\pgfmathprintnumber\ABl,-6pt,}](A,B)
\end{scope}
\tkzLabelPoints(A,B) \tkzLabelPoints[above](C)
\end{tikzpicture}
\begin{tikzpicture}[scale=.75]
\tkzDefPoints{0/0/O,-2/0/A,2/0/B,
-2/4/C,2/4/D,2/-4/E,-2/-4/F}
\tkzDrawPolygon(C,...,F)
\tkzDrawSegments(A,B)
\tkzDrawPoints(A,...,F,O)
\tkzLabelPoints(A,...,F,O)
\tkzDrawSegment[dim={ $\sqrt{5}$,2cm,}](C,E)
\tkzDrawSegment[dim={ $\frac{\sqrt{5}}{2}$,1cm,}](O,E)
\tkzDrawSegment[dim={ $2$,2cm,left=8pt}](F,C)
\tkzDrawSegment[dim={ $1$,1cm,left=8pt}](F,A)
\end{tikzpicture}
\end{document}
答案2
这很容易实现pstricks
:
\documentclass[border=6pt, svgnames]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(0,-2.5)(9,1.5)
\psset{arrowinset=0}
\pstGeonode[PointSymbol=*, PosAngle=-90, linecolor=DodgerBlue](1,0){A}(2.3,0){B}(5,0){C}(8,0){D}
\pstLineAB[nodesepA=-1, nodesepB=-1, arrows=<->]{A}{D}
\psset{arrows=|<->|}
\ncline[offset=0.8cm]{A}{D}\ncput*{24 cm}
\ncline[offset=-0.8cm]{A}{C}\ncput*{15 cm}
\ncline[offset=-1.3cm]{B}{D}\ncput*{17 cm}
\end{pspicture}
\end{document}
答案3
我会这样解决
\begin{tikzpicture}[vect/.style={<->,
shorten >=1pt,>=latex},vect1/.style={|<->|,
shorten >=1pt,>=latex},scale=1]
\tkzDefPoint(0,0){O}
\tkzDefPoint(9,0){Z}
\tkzDefPoint(1,0){A}
\tkzDefPoint(8,0){D}
\tkzDefPoint(2.3,0){B}
\tkzDefPoint(5,0){C}
\tkzDefPoint(1,0.5){A1}
\tkzDefPoint(8,0.5){D1}
\tkzDefPoint(1,-0.6){A2}
\tkzDefPoint(5,-0.6){C2}
\tkzDefPoint(2.3,-1.2){B2}
\tkzDefPoint(8,-1.2){D2}
\tkzDrawSegments[thick,vect](O,Z)
\tkzDrawPoints[color=blue](A,B,C,D)
\tkzLabelPoints[below](A,B,C,D)
\tkzDrawSegments[vect1](A1,D1 A2,C2 B2,D2)
\path[coordinate] (A1) -- (D1) coordinate[pos=.5](F);
\node[fill=white] at (F) {24cm};
\tkzLabelSegments[below](A2,C2){15 cm}
\tkzLabelSegments[below](B2,D2){17 cm}
\end{tikzpicture}
答案4
为什么我们不使用简单的 TikZ?
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[>=stealth]
\draw[<->,thick] (-1,0)--
(0,0) coordinate (A) node[below]{$A$}--
(5,0) coordinate (B) node[below]{$B$}--(6,0);
\foreach \p in {A,B} \fill[red] (\p) circle(1.5pt);
\draw[|<->|,gray]
([shift={(0,.5)}]A)--([shift={(0,.5)}]B)
node[midway,fill=white,text=blue,scale=.8]{5 cm};
\end{tikzpicture}
\end{document}