# How to fix TikZ node's height with \heightof?

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?

-
Don't use minimum height (or add \depthof to \heightof). Use text depth and text height. For example: text height=1em,text depth=.2em. – Paul Gaborit Oct 19 '12 at 9:52
@PaulGaborit: OK, with text height=\heightof{Cap} and text depth=\depthof{Cap} I obtain equal height nodes, but why minimum height=\heightof{Cap} doesn't work? As you can see in my result empty nodes are shorter than C. – Ignasi Oct 19 '12 at 10:38
@PaulGaborit: Tom answered my question, If I fix minimum heigth I must include inner sep in it for empty nodes. – Ignasi Oct 19 '12 at 11:08
Actually, it seems to already do this, see my edit. – Tom Bombadil Oct 19 '12 at 15:54

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

-
Understood! Do you know how to consider font size? Something like \heightof{\Large{Cap}}. – Ignasi Oct 19 '12 at 11:12
No, it doesn't consider fontsize. It works for you because you change \myinnersep. Try with minimum height=\heigthof{Cap}+\depthof{Cap} and \myinnersep=0, it should draw a 'tight' Cap box and it does only for normalsize font. – Ignasi Oct 19 '12 at 17:38
Nice solution. Can it be done generically? I.e. without having manually provide the contents of the largest node to the minimum height? But rather that it equalises the sizes of the boxes based on the largest node? – Frederick Nord Apr 15 '14 at 13:51
@FrederickNord: New questions made within comments have difficult visibility, it's better that you make it as a new question with link to this answer. – Ignasi Apr 16 '14 at 7:40
heightof is not longer working with TikZ, the new command is height("Cap") – maetra Feb 10 at 10:28