这可能是两个密切相关的问题中的第一个。
我定义了一种风格:
my node style/.style={%%
minimum width=\dimexpr0.60in+12pt\relax,
minimum height=\dimexpr0.30cm+12pt\relax,
outer sep=0pt,
draw},
我不想在表格的每个单元格内声明节点样式;相反,我更喜欢使用如下键来执行此操作:
row 3 column 2/.style={my node style}
但是,当我这样做时,my node style
除了draw
(当在我想要应用它的每个单元格内声明此节点样式时不存在这样的问题)之外的所有内容都会生效。
下面是一个说明此问题的 MWE:
\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}
答案1
my node style
需要进入nodes={}
键。单元格没有draw
属性,但单元格内的节点有。因此,需要将其传递给要在单元格中绘制的节点。最简单的机制就是键nodes
。
因此唯一需要修改的是
row 3 column <col no>/.style={nodes={my node style}},
答案2
或者你也可以将选项添加nodes=draw
到my node style
。那么单元格内的节点也将被绘制。
my node style/.style={%%
minimum width=\dimexpr0.60in+12pt\relax,
minimum height=\dimexpr0.30cm+12pt\relax,
outer sep=0pt,
draw,
nodes=draw}