我正在尝试通过无边框节点在 Tikz 矩阵中创建一个空白行,并填充白色。但是这个节点像图片一样切断了前一行分隔线的一半。如果我更改关键节点(test-3-1)的高度,它会影响整行。该属性outer sep=\pgflinewidth
不起作用。有什么方法可以添加空白行吗?
梅威瑟:
\documentclass[margin=5mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
minimum height=1em,% This needed for alignment
text depth=0pt,
text height=1ex,
nodes={
rectangle,
draw=black,
align=center
},
every odd row/.style={% This needed for working code
nodes={fill=gray!20}
},
row 3 column 1/.style={
nodes={fill=white, draw=none}
},
}
}
\begin{tikzpicture}
\matrix (test) [table, text width=1em] {
~ & ~ & ~ & ~ \\
~ & ~ & ~ & ~ \\
~ & & & \\
~ & ~ & ~ & ~ \\
};
\end{tikzpicture}
\end{document}
答案1
在这种情况下,我认为您只需设置fill=none
在第三行。
\documentclass[margin=5mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
minimum height=1em,% This needed for alignment
text depth=0pt,
text height=1ex,
nodes={
rectangle,
draw=black,
align=center
},
every odd row/.style={% This needed for working code
nodes={fill=gray!20}
},
row 3 column 1/.style={
nodes={draw=none,fill=none} % <------- here
},
}
}
\begin{tikzpicture}
\matrix (test) [table, text width=1em] {
~ & ~ & ~ & ~ \\
~ & ~ & ~ & ~ \\
~ & & & & \\
~ & ~ & ~ & ~ \\
};
\end{tikzpicture}
\end{document}