⚉ DWIM Atom feed

DWIM — Trying to make the computer Do What I Mean

Bracing some elements in a matrix

A friend asked me today if this was possible, to which I answered "probably, just use a \phantom". Though it isn't as clean as I'd hoped, the following code allows you to achieve the effect in the picture. The text inside the \phantom command has to change in order to grow the brace. You should insert the text exactly as you insert it in the "real" matrix (with the Math-mode delimiters as needed) and add \hspace{2\tabcolsep} where you'd put "&".
brace over over elements in a matrix
      a & \smash{\rlap{$\overbrace{\phantom{b\hspace{2\tabcolsep}c
      \hspace{2\tabcolsep}d}}^{Blah}$}}b & c & d\\
      e & f & g & h

How/why this works: Before the "b", we create some phantom text (or rather a phantom box, I guess) which we then overbrace. A phantom box or text is one that takes up its normal space but doesn't print any text. In order to have this box be the proper size, we write whatever needs to be braced just as we'd write it if we were overbracing normal text, but inserting \hspace{2\tabcolsep} where the "&" would usually go. This command adds the right spacing between two fields (there is \tabcolstep space before and after each field)
The first trick is to use \overbrace on that phantom box. Once we have that, we use \rlap on it (the surrounding box which includes the brace) to collapse it horizontally (that is, to make its "virtual" horizontal space zero) so the text that we actually want to brace starts at the right place.

With this, the line is still too high, which means the braces climb too much. With the \smash macro around the whole thing we collapse it vertically, so that the bracing has no effect on how tall the array thinks it should be.
And there we have it, a relatively simple way to put a brace around a few element in a matrix without modifying the braces' height.

Carlos Martín Nieto <cmn@dwim.me>