Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
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
add comment

1 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

share|improve this answer
    
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 2 days ago
    
@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 yesterday
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.