I am using the solution form Obstacles to simulating an amsmath matrix by a TiKZ matrix of math nodes to create a tikz matrix in the style of a bmatrix.
I would like to leave a little extra space after the last line and thought that using \\[1.5ex] should do the job:
\matrix (m) {
1 & 4 \\
7 & 10 \\
13 & 16 \\[1.5ex]% <--- This seems to have no effect.
};
but that does not seem to have any effect. Using this optional parameter to any line but the last seems to work.
The bmatrix version behaves as desired.
Related Question
- Adjust top and bottom of tikz matrix's left delimiter and right delimiter individually
- How to increase row height while using booktabs?. This is not about
tikzbut similar issue of vertical spacing.
Code:
\documentclass{article}
\usepackage{mathtools}% for amsmath {bmatrix}
\usepackage{tikz}
\usetikzlibrary{matrix}
%% https://tex.stackexchange.com/questions/26866/obstacles-to-simulating-an-amsmath-matrix-by-a-tikz-matrix-of-math-nodes
\newlength\mtxrowsep \setlength\mtxrowsep{1.5ex}
\newlength\mtxcolsep \setlength\mtxcolsep{2\arraycolsep}
\tikzset{
ams/.style={
baseline=-.7ex,
every delimiter/.style={yshift=-1pt},
every left delimiter/.style={xshift=2pt},
every right delimiter/.style={xshift=-2pt},
every node/.style={inner sep=0pt},
},
ams matrix/.style={
inner sep=1pt,
column sep=\mtxcolsep,
row sep=\mtxrowsep,
% Following is also commented at https://tex.stackexchange.com/questions/26866
%ampersand replacement=&,
matrix of math nodes,
},
bmatrix/.style={
ams,
every matrix/.style={
ams matrix,
left delimiter={[},
right delimiter={]},
}
},
Bmatrix/.style={
ams,
every matrix/.style={
ams matrix,
left delimiter={\lbrace},
right delimiter={\rbrace},
}
},
pmatrix/.style={
ams,
every matrix/.style={
ams matrix,
left delimiter={(},
right delimiter={)},
}
},
vmatrix/.style={
ams,
every matrix/.style={
ams matrix,
left delimiter={|},
right delimiter={|},
}
},
Vmatrix/.style={
ams,
every matrix/.style={
ams matrix,
left delimiter={|},
right delimiter={|},
}
},
}
%% This does not seem to be necessary here
%\let\matamp=&
%
%\catcode`&=13
%\makeatletter
%\def&{\iftikz@is@matrix
% \pgfmatrixnextcell
% \else
% \matamp
% \fi}
%\makeatother
\begin{document}
\hspace{0.2em}
\begin{tikzpicture}[bmatrix]
\matrix (m) {
1 & 4 \
7 & 10 \
13 & 16 \[1.5ex]% <--- This seems to have no effect.
};
\end{tikzpicture}
%% ----------------
\hspace{0.3em}
$\begin{bmatrix}
\smash{1} & \smash{4} \
7 & 10 \
13 & 16 \[1.5ex]
\end{bmatrix}$
tikz matrix \hspace*{0.6em} bmatrix
\end{document}
Temporary Addendum:
I attempted to use Qrrbrbirlbel's solution, but ran into a problem : the coordinates of the nodes are no longer where tikz thinks they are. Using the preamble provided in the answer with the following code, it seems that the nodes (eg. m-1-1.north west) are shifted:
\newcommand{\FillMatrix}{%
\fill [rounded corners=3pt, fill opacity=.35, fill=green!80]
([shift={(0pt, 2pt)}]m-1-1.north west)
-- ([shift={(0pt,-2pt)}]m-2-1.south west)
-- ([shift={(2pt,-2pt)}]m-2-2.south east)
-- ([shift={(2pt, 0pt)}]m-2-2.north east)
-- cycle;
}%
\begin{document}
\hspace{0.2em}
\begin{tikzpicture}[bmatrix]
\matrix (m) {
1 & 4 \
7 & 10 \
13 & 16 \[-2pt]
};
\FillMatrix
\end{tikzpicture}
%% ----------------
\hspace{0.3em}
\begin{tikzpicture}[bmatrix, matrix bottom crcr]
\matrix (m) {
1 & 4 \
7 & 10 \
13 & 16 \[-2pt]
};
\FillMatrix
\end{tikzpicture}
\hspace{0.6em} default \hspace{0.6em} matrix bottom crcr
\end{document}



13 & 16 \\[0ex]\\works, you can then adjust the length as required – David Carlisle Jan 03 '24 at 21:36row sepif you use an extra\\) or a more automatic approach (like anadd bottom space=1.5ex). – Qrrbrbirlbel Jan 03 '24 at 23:30\\[-1.14pt] \\and\\[-1.15pt] \\. What is going on? – Peter Grill Jan 04 '24 at 05:05row sepas long as I could take it away with a negative amount. Perhaps that is the issues with the quantized jumps I am seeing. – Peter Grill Jan 04 '24 at 05:07