I have a node style I would like to apply to many (but not all) the cells/columns/rows of a matrix of nodes. Currently, for every column or cell that I want the style to apply to, I declare the style as:
column 2/.style={column sep=-0.4pt},
column 3/.style={column sep=-0.4pt},
column 4/.style={column sep=-0.4pt},
column 5/.style={column sep=-0.4pt},
row 3 column 2/.style={my node style},
row 3 column 3/.style={my node style},
row 3 column 4/.style={my node style},
row 3 column 5/.style={my node style},
row 3 column 6/.style={my node style},
It would be more convenient if I could write something like
column 2 to 5/.style={column sep=-0.4pt},
row 3 column 2 to 5/.style={my node style},
row 4 column 2 to 5/.style={my node style},
or even better (for the last two)
cell 3 2 to cell 4 5/.style={my node style},
Here's a MWE where such keys would improve readability of the code
\documentclass[border=6pt]{standalone}
\usepackage{amsmath}
\newcommand\abs[1]{\lvert#1\rvert}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows.meta}
\tikzset{%%
>=Stealth,
my node style/.style={%%
minimum width=\dimexpr0.60in+12pt\relax,
minimum height=\dimexpr0.30cm+12pt\relax,
outer sep=0pt,
draw},
}
\begin{document}
\begin{tikzpicture}
\matrix (TBL) [%%
matrix of nodes,
nodes={%%
align=center,
inner sep=0pt,
anchor=center},
column 2/.style={column sep=-0.4pt},
column 3/.style={column sep=-0.4pt},
column 4/.style={column sep=-0.4pt},
column 5/.style={column sep=-0.4pt},
row 3 column 2/.style={my node style},
row 3 column 3/.style={my node style},
row 3 column 4/.style={my node style},
row 3 column 5/.style={my node style},
row 3 column 6/.style={my node style},
]
{
& {$(-\infty,-2)$} & {$(-2,-1)$} & {$(-1,1)$} & {$(1,2)$} & {$(2,\infty)$} \\[2pt]
{$\abs{x^{2}-1}=\,$} & |[my node style]| {$x^{2}-1 $} & |[my node style]| {$x^{2}-1$} & |[my node style]| {$1-x^{2}$} & |[my node style]| {$x^{2}-1$} & |[my node style]| {$x^{2}-1$} \\[-0.4pt]
{$\abs{x^{2}-4}=\,$} & {$x^{2}-4 $} & {$4-x^{2}$} & {$4-x^{2}$} & {$4-x^{2}$} & {$x^{2}-4$} \\[2pt]
{$g(x) =$} & |[my node style]| {$ 3 $ } & |[my node style]| {$ 2x^{2}-5$} & |[my node style]| {$ -3 $} & |[my node style]| { $2x^{2}-5$} & |[my node style]| {$ 3 $} \\
};
\end{tikzpicture}
\end{document}
Note: I'm also trying to avoid having to declare the style explicitly in each cell where I want it to apply as in rows 2 and 4 of the above example.
UPDATE
I've tried adding the following to my preamble
\tikzset{%%
column \the\pgfmatrixcurrentcolumn\space to \the\pgfmatrixcurrentcolumn/.try,
}
but when I try to call it as in:
\begin{tikzpicture}
\matrix (TBL) [%%
matrix of nodes,
nodes={%%
align=center,
inner sep=0pt,
anchor=center},
column 2/.style={column sep=-0.4pt},
column 3/.style={column sep=-0.4pt},
column 4/.style={column sep=-0.4pt},
column 5/.style={column sep=-0.4pt},
row 3 column 2/.style={my node style},
row 3 column 3/.style={my node style},
row 3 column 4/.style={my node style},
row 3 column 5/.style={my node style},
row 3 column 6/.style={my node style},
column 2 to 5/.style={red},
]
{
& {$(-\infty,-2)$} & {$(-2,-1)$} & {$(-1,1)$} & {$(1,2)$} & {$(2,\infty)$} \\[2pt]
{$\abs{x^{2}-1}=\,$} & |[my node style]| {$x^{2}-1 $} & |[my node style]| {$x^{2}-1$} & |[my node style]| {$1-x^{2}$} & |[my node style]| {$x^{2}-1$} & |[my node style]| {$x^{2}-1$} \\[-0.4pt]
{$\abs{x^{2}-4}=\,$} & {$x^{2}-4 $} & {$4-x^{2}$} & {$4-x^{2}$} & {$4-x^{2}$} & {$x^{2}-4$} \\[2pt]
{$g(x) =$} & |[my node style]| {$ 3 $ } & |[my node style]| {$ 2x^{2}-5$} & |[my node style]| {$ -3 $} & |[my node style]| { $2x^{2}-5$} & |[my node style]| {$ 3 $} \\
};
\end{tikzpicture}
There is no apparent effect.