[Tex/LaTex] How to fix TikZ node’s height with \heightof

lengthstikz-pgf

I can use \widthof{text} to fix a minimum width of a TikZ's node. I would like to use \heightof{text} to fix its minimum height but it doesn't work.

I just want to fill my nodes with one word but I want to draw some empty nodes with same height as filled ones. But I would like not to use a trial and error system to fix it's size.

Next code shows what I want to do. I've tried uncommenting \usepackage{calc} but nothing changed. .log file doesn't show any error about knowing or not command \heightof.

A possible solution would be to use \vphantom{text} inside empty nodes, but I would like to know what's wrong with this one.

\documentclass[tikz,border=1mm]{standalone}
%\usepackage{calc}
\usetikzlibrary{positioning}

\tikzset{
box/.style={draw,%
    minimum width=5mm,%
    minimum height=\heightof{Cap},%
    align=center},
}

\begin{document}
\begin{tikzpicture}[font=\small\sffamily]

\node[box] (h0) {Cap};
\foreach \i [remember=\i as \lastx (initially 0)] in {1,...,6} 
    \node[box,right= 0mm of h\lastx] (h\i) {};
\node[box,right=0mm of h\lastx] {cua};

\end{tikzpicture}
\end{document}

This is the result. You can see that minimum height is not fixed with \heightof. Why?

enter image description here

Best Answer

The minimum height ist the total height, not taking into account the inner sep of the nodes. Setting the outer sep to zero will align them nicely:

Code

\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{positioning}

\pgfmathsetmacro{\myinnersep}{2}% inner sep in mm

\tikzset{
box/.style={draw,%
        inner sep=\myinnersep,%
        outer sep=0,%
    minimum width=5mm,%
    minimum height=\heightof{Cap}+2*\myinnersep*1mm,%
    align=center}
}

\begin{document}
\begin{tikzpicture}[font=\small\sffamily]

\node[box] (h0) {Cap};
\foreach \i [remember=\i as \lastx (initially 0)] in {1,...,6} 
    \node[box,right= 0mm of h\lastx] (h\i) {};
\node[box,right=0mm of h\lastx] {cua};

\end{tikzpicture}
\end{document}

Output

enter image description here