TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have problems controlling the exact height of an \hbox; what is wrong with this example?


\fbox{ \vbox to #1cm{
       \vfil\hbox to 1cm {\hfill #2 \hfill}


\mybox{2}{a} & 


I expected the total height of the two boxes on the right to be the same as the height of the left box, namely 2cm. However, there seem to be a hidden height which is added. How can I control this?


Thanks for the quick and detailed replies, it helped a lot!

However, there is still another problem:



    \fcolorbox{black}{#2}{\parbox[#1][\mylenA][c]{\mylenB}{\centering #4}}}



 & \mybox{blue}{4}{C}
& \mybox{red}{8}{D}


The left and right brackets are way to large; does anyone see what goes wrong?

And, second, is there a more elegant way of setting arraycolsep and the newline


automatically to the correct value? I want the boxes to be as close as possible, vertically and horizontally.

share|improve this question
2\frulewidth+2\frulesep – Danie Els Jun 10 '11 at 1:12
Welcome to tex.sx! A tip: If you indent lines by 4 spaces, then they are marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it), and you can use backticks ` to mark your inline code as I did in my edit. – Gonzalo Medina Jun 10 '11 at 1:30
Sorry it is 2\fboxrule+2\fboxsep – Danie Els Jun 10 '11 at 1:31
@Heiko: Your answer post created a new unregistered account (with the same name and icon). I merged both together now and moved your post to the question. Please consider to register your account to avoid such issues. Thanks. – Martin Scharrer Jun 10 '11 at 7:29
I'd like to thank everyone for these most helpful suggestions! I'm still not used to this editor here, but at least now I'm registered ;) – Heiko Jun 10 '11 at 9:20

You are not taking into account \fboxsep (the separation between the framed box and its contents; default value: 3pt) and the "thickness" of the rules used (\fboxrule: 0.4pt, by default). If you set \fboxsep to 0pt, then the box on the right will have a total height of 2cm+0.4pt while the two stacked boxes on the left will have a total height of 1cm+1cm+(4*0.2pt)=2cm+0.8pt (if the middle horizontal rules don't overlap, but are immediately next to each other) or 1cm+1cm+(3*0.2pt)=2cm+0.6pt (if the middle horizontal rules overlap).

EDIT: by the way, instead of using $$...$$ for displayed math, you should use \[...\].

EDIT2: although I think that sometimes TikZ is overused, in this particular case I think that it would be sensible to give it a try (it facilitates the exact placement of the colored boxes):




\def\MyBox#1#2#3#4{\node[draw,fill=#1,minimum width=#2\MyUnit,minimum height=#2\MyUnit,align=center] at (#4) {#3};}

\matrix [matrix of nodes,left delimiter=(,right delimiter=)]



enter image description here

share|improve this answer

Do not use the Tex primatives \vbox and \hbox in directly in latex, because they are not color "save". Use the latex equavalents \parbox, \makebox, and minipage.

The code below gives you a ruled box with required outer dimension (including the rule width and separation)


Rather use the picture environment to add your boxes, then you have more control


    \fcolorbox{black}{#2}{\parbox[#1][\mylenA][c]{\mylenB}{\centering #4}}}


    \put(0, 2){\mybox[c]{yellow}{4}{A}}
    \put(4, 2){\mybox[c]{green}{4}{B}}
    \put(8, 0){\mybox[c]{red}{8}{D}}

enter image description here

share|improve this answer

Your Answer


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.