# Adding dimensions to TikZ pictures

How do you add dimension labels to TikZ pictures? Ideally, it would look something like this:

|<----- dimension ----->|


I would like to do this to show the measurement of both straight lines (i.e. sides of a polygon) and curved lines (i.e. circumference/arc length on a circle). Thanks in advance for your help!

For educational and show-off purposes only!

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


• This is really nice, if this continues further we will replace 2D CAD with TikZ. – Alexander Jul 13 '13 at 20:05
• @Alexander I wish :-) But this is just showing off, under some pressure, it will disappoint you rather quickly. – percusse Jul 13 '13 at 20:09
• Thanks for the detailed response! One more thing though: is it possible to add arrows to the end of the lines? – Randy Randerson Jul 13 '13 at 20:23
• @fctaylor25 Add <-> in the \draw options. – percusse Jul 13 '13 at 20:38
• Is there any way to make the measurement a variable (e.g. C for circumference, h for height, etc.)? – Randy Randerson Jul 14 '13 at 0:41