列样式中忽略绘制和填充选项

列样式中忽略绘制和填充选项

在 tikz 矩阵中提供时,和选项会被忽略,但颜色和其他选项不会被draw忽略:fillcolumn 1/.styletext

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
  \matrix[matrix of nodes, column 1/.style={draw=red, fill=blue, text=green}] {
    A & B \\
    C & D \\
  };
\end{tikzpicture}
\end{document}

矩阵包含 ABCD,其中 A 和 C 为绿色,但没有边框也没有填充

为什么会发生这种情况?我该如何解决?

答案1

样式column 1不应用于第 1 列条目中的节点,而是应用于单元格。使用标准矩阵(即不是带有 的矩阵matrix of nodes),单元格可以包含除节点之外的其他内容,因此样式必须更通用。因此,您应该将单元格视为范围,而不是路径。要影响范围内的节点,您需要使用键every node/.style={...}。也就是说,如果您想使用范围来影响节点,请编写:

\begin{scope}[every node/.style={draw=blue}]
\node {This will have a blue outline};
\end{scope}

因此,您需要对矩阵执行相同的操作。因此column 1/.style={every node/.style={draw = red, fill = blue, text = green}}是正确的。它可能看起来有点笨重,但它的存在是因为单元格内容具有更大的灵活性。

如果还没有(如果不看手册我就不知道)那么您可以定义一种column 1 nodes为您完成双重功能的样式。

\documentclass{article}
%\url{http://tex.stackexchange.com/q/133636/86}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
  \matrix[matrix of nodes, column 1/.style={every node/.style={draw=red, fill=blue, text=green}}] {
    A & B \\
    C & D \\
  };
\end{tikzpicture}

\tikzset{column 1 nodes/.style={column 1/.style={every node/.style={#1}}}}

\begin{tikzpicture}
  \matrix[matrix of nodes, column 1 nodes={draw=red, fill=blue, text=green}] {
    A & B \\
    C & D \\
  };
\end{tikzpicture}
\end{document}

答案2

您必须明确地将属性分配给矩阵的节点。尝试类似这样的操作。

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
  \begin{tikzpicture}
    \matrix[matrix of nodes, column 1/.style={nodes={draw=red, fill=blue, text=green}}] {
      A & B \\
      C & D \\
    };
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容