I'm trying to draw a simple rectangle together with the dimensions. Here is my first try:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro{\a}{2.0}
\pgfmathsetmacro{\b}{4.0}
\begin{tikzpicture}
\draw (0, 0) rectangle (\a, \b);
\draw[|<->|] (0, 0) -- ++ (\a, 0);
\node[below] at (0.5*\a, 0) {a};
\end{tikzpicture}
\end{document}
This of course results in the line drawn on top of the rectangle, but I would like it to be a bit below. Sure, I could do something like
\draw[|<->|] (0, -5mm) -- ++ (\a, 0);
but this is neither very nice nor does it scale correctly. Any suggestions?
Edit: Heres is an example of what I mean by not scaling correctly:
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro{\a}{2.0}
\pgfmathsetmacro{\b}{4.0}
\begin{tikzpicture}[scale=1]
\draw (0, 0) rectangle (\a, \b);
\draw[|<->|] ([yshift=-1mm]0, 0) -- ++ (\a, 0);
\node[below] at (0.5*\a, 0) {a};
\end{tikzpicture}
\begin{tikzpicture}[scale=5]
\draw (0, 0) rectangle (\a, \b);
\draw[|<->|] ([yshift=-1mm]0, 0) -- ++ (\a, 0);
\node[below] at (0.5*\a, 0) {a};
\end{tikzpicture}
\end{document}
measure
key would be great, with an optional distance, e.g.,\draw[measure] (0,0) -- (1,0);
automated, and[measure=1cm]
in case one wants to decide the distance, but I don't know how to program it.measure
won't do, because how would it know when to place it above, below, left or right? Regardless, mytikz
foo is too weak, hence this question.