I have a matrix enclosed in brackets [ ]
(or ()
, or {}
, or |
's, or ||
's):
- a b c d -
| e f g h |
| i j k l |
- m n o p -
which I want to label like so:
R
|---|
-- - a b c d -
A| | e f g h |
-- | i j k l |
- m n o p -
Where the dashes by the labels are meant to be giant {'s as in this picture:
How can I do this?
Although two answers have been provided that work to an extent, I've added a bounty because I'd like to see if anyone has, or can come up with, a neat, robust solution.
Best Answer
The following solution uses TikZ, but a minimal amount of hacks:
First two tikz libraries are loaded (this only needs to be done once). In the
tikzpicture
environment a matrix calledm
is defined. The delimiters can be changed to anything that is acceptable after\left
in math mode. Entries of the matrix can be reference byname-row-column
(where in this case the name ism
). I found good looking shifts (i.e. the distances between brace and matrix entry) by trail-and-error; you might have to change them. Also you might want to try removing thethick
parameter.I tried wrapping the whole stuff in nice commands. Unfortunately I only succeeded partially, because I do not know how to handle the
&
in the matrix without LaTeX complaining about "misplaced alignment tab character". I tweaked the spacing in the following tikz styles a bit to make the matrix look more like the usual ones. Maybe there are better ways to do this (are all the lengths the (usual) matrix environment used accessible somehow?).Anyway, on to the commands. Put the following wall of code somewhere near the beginning of the document:
After that, you can simply use the following code to produce your example:
The matrix definition remained pretty much the same as before, except that all the styles needed are now stored in
mymatrixenv
andmymatrix
. No need to repeat them for every matrix!The braces are produced with
\mymatrixbraceright
,\mymatrixbracetop
,\mymatrixbraceleft
and\mymatrixbracebottom
for right, top, left and bottom braces respectively. The commands all work the same way: They have three mandatory commands for starting and ending position of the brace (in "natural" order) and the label. Additionally they have one optional argument for specifying the name of the matrix (it defaults tom
). So, if you want a brace on the left of matrixfoo
going from the row 3 to row 417 and with label$415$ rows!
, you use