为 TikZ 图片添加尺寸

为 TikZ 图片添加尺寸

如何向 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}

在此处输入图片描述

相关内容