
TikZ 画像に寸法ラベルを追加するにはどうすればよいでしょうか。理想的には、次のようになります。
|<----- dimension ----->|
私は直線(多角形の辺など)と曲線(円周/円弧の長さなど)の両方の測定値を表示するためにこれを実行したいと思います。ご協力をよろしくお願いします。
答え1
教育および披露目的のみに使用してください。
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{measure length/.style={
decoration={markings,
mark connection node=a,
mark =at position 0.5 with {
\node[transform shape,fill=white,scale=0.5,#1] (a)
{\pgfmathparse{\pgfdecoratedpathlength/2.845274}%
\pgfmathprintnumber[fixed,precision=1]\pgfmathresult mm};},
},
postaction=decorate
}
}
\begin{document}
\begin{tikzpicture}
\draw[measure length] (-2,-2cm) -- (2cm,-2cm);
\draw[measure length={rotate=180}] (0,0) arc (0:270:1cm) ;
\draw[measure length={rotate=180}] (0,3) arc (0:270:1cm) -- ++(10mm,0);
\foreach \x in {0,...,5}{
\draw[measure length] (2,2) +(\x*60:1cm) -- +({(\x+1)*60)}:1cm);
}
\end{tikzpicture}
\end{document}