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. This works pretty well, with the default specification of
every delimiter/.style={yshift=-1pt}.
But, sometimes I want to manually tweak the top of the left/right delimiter separately form the bottom of the left/right delimiter so trying to find a tikz way of doing that. I could hack it by placing a phantom vertical rule, but would be much nicer to have a tikz style for that. Ideally, the solution would have style such as the following:
left delimiter top y shift=
left delimiter bottom y shift=
right delimiter top y shift=
right delimiter bottom y shift=
and similarly for the associated ones for the top and bottom delimiters (which are not used here)
top delimiter left x shift=
top delimiter right x shift=
bottom delimiter left x shift=
bottom delimiter right x shift=
Just to be clear, I am not expecting an automated solutions, but a manual tweaking of the delimiters as needed.
Below is a contrived example (and much to my surprise bmatrix produces the desired results by default, but don't understand how) where the first line of the matrix for both cases is
\smash{1} & \smash{4} \\
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
%\let\matamp=&
%
%\catcode`&=13
%\makeatletter
%\def&{\iftikz@is@matrix
% \pgfmatrixnextcell
% \else
% \matamp
% \fi}
%\makeatother
\begin{document}
\hspace{0.2em}
\begin{tikzpicture}[bmatrix]
\matrix (m) {
\smash{1} & \smash{4} \
7 & 10 \
13 & 16 \
};
\end{tikzpicture}
%% ----------------
\hspace{0.3em}
$\begin{bmatrix}
\smash{1} & \smash{4} \
7 & 10 \
13 & 16 \
\end{bmatrix}$
tikz matrix \hspace*{0.6em} bmatrix
\end{document}


nicematrixreplace a lot of TikZ matrices? You're talking about top and bottom delimiters but don't use them. Do you mean the top and bottom end of the left and right delimiters? The\smashreduces the TikZ nodes and therefore the whole row to zero height whilebmatrixprobably still counts the row as a row. There might be a better way than\smash. Why do you need it? – Qrrbrbirlbel Dec 22 '23 at 14:47\left[ <zero width box of measured height/depth> \right.that placed at one of the four sides of the node (And we could adopt this to measure anything and place that anyway.) How should the delimiter be drawn without any knowledge of some vertical dimension of the first row? At least a\(math)strutsomewhere? If you use\smash{\dfrac{1}{2}}with thebmatrixit won't look good anymore as well. – Qrrbrbirlbel Dec 22 '23 at 14:57left delimiterand the bottom of theleft delimeter(and similarly for theright delimeter). The default behavior is what is expected. The reason I need it is theyshift=-1ptseems to be fine in most cases, but not all cases. Thus, the desire to manually tweak the top and bottom separately. – Peter Grill Dec 22 '23 at 18:15