I'm trying to figure out a TiKZ
-based solution to this problem involving arrows between matrix rows. To this end, I would like to at least be able to make a matrix of math nodes
simulate the behaviour of the matrix
environment from amsmath
.
I have encountered several problems in doing so. One of them is the appearance of the matrices themselves and their relation to the surrounding text. Consider the following example:
\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix}
\newlength\mtxrowsep \setlength\mtxrowsep{2ex}
\newlength\mtxcolsep \setlength\mtxcolsep{\arraycolsep}
\begin{document}
\begin{gather*}
4 \times
\left[\begin{matrix} a & b \\ c & d \end{matrix}\right]
\qquad
4 \times
\left[\begin{tikzpicture}
\matrix [matrix of math nodes, ampersand replacement=\&,
inner sep=0pt, column sep=\mtxcolsep, row sep=\mtxrowsep]
{ a \& b \\ c \& d \\ };
\end{tikzpicture}\right]
\qquad
4 \times
\left[\begin{minipage}{1.7em}
{}\hfill\begin{tikzpicture}
\matrix [matrix of math nodes, ampersand replacement=\&,
inner sep=0pt, column sep=\mtxcolsep, row sep=\mtxrowsep]
{ a \& b \\ c \& d \\ };
\end{tikzpicture}\hfill{}
\end{minipage}\right]
\end{gather*}
\end{document}
This produces the following output:
The genuine amsmath
matrix is on the left. The matrix in the middle suffers from the fact that the matrix of math nodes
in the tikzpicture
environment is apparently sitting on top of the baseline of the surrounding math. The matrix on the right is properly aligned because it is sitting inside of a minipage
, whose width was manually specified. (Not pictured is anything using left delimiter
or right delimiter
, which has spacing issues of its own and suffers from the same vertical alignment issues.)
Main questions.
Is there any way native to
tikz
to change the vertical alignment of thetikzpicture
for the matrix in the middle? (I didn't find anything whilst scanning through the manual...)Is there any way to extract the width of an image automatically, to allow automatic resizing of the
minipage
for the matrix on the right?
text height
andtext depth
?tikz
adept, but is the\` after the
c \& d` in thetikz
version necessary?