I have the following TiKZ code:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand{\delim}[1]{\draw(#1,-0.2) -- (#1,-0.5);}
\draw (0,0) rectangle (1,1);
\draw (1,0) rectangle (2,1);
\delim{0}
\delim{2}
\node[below] at(0,0){\small Unused};
\end{tikzpicture}
\end{document}
This results in this image:
But I'd like to center the text between the two boxes, sort of like this image:
How do I do this?
Best Answer
The text is centered under
(0,0)
which is the coordinate you provided. I think you want to use(1,0)
:If you want thicker lines, you use
[thick]
,[ultra thick]
options, or specify an line width as[line width=2pt]
:Another method is to modify the
\delim
macro to take a second parameter and use that to label the center of the line segments,A
andB
in the example below. Then you can compute the midpoint of the two points using($(A)!0.5!(B)$)
and place the text at that position. This solution has the added benefit that if you change the coordinates in the\delim
macro, the text will be centered between the two points.Note that this requires
\usetikzlibrary{calc}
in the preamble.