為 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}

在此輸入影像描述

相關內容