矩阵单元名称不可用

矩阵单元名称不可用

我尝试在矩阵中使用多部分节点,并用单元格名称绘制线条。以下代码报告错误:(使用纯文本可以正常工作)

 Package pgf Error: No shape named `m-1-1' is known.



See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                
l.19     \draw (m-1-1.north west)

                                -- (m-1-2.north east) -- (m-1-2.south east...

代码:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart, matrix,fit,backgrounds}
\tikzset{
    box/.style={
        shape=rectangle split, rectangle split parts=4
    },
}
\newcommand{\parts}[4] {
    \node[box] {\nodepart{one} #1 \nodepart{two} #2 \nodepart{three} #3 \nodepart{four} #4};
}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,column sep=-\pgflinewidth, row sep=-\pgflinewidth,
    draw,align=center] (m)
{
    \parts{AAA}{BBB}{CCC}{DDD}  &  \node{EEEEEE}; \\
};
    \draw (m-1-1.north west) -- (m-1-2.north east) -- (m-1-2.south east) -- (m-1-1).north west) -- cycle;
\end{tikzpicture}
\end{document}

答案1

在 中matrix of nodes\node (<name>-<row>-<col>) {<content>};已为您插入。如果您以反斜杠开始单元格的内容,则会覆盖此内容,但命名显然由您决定。

更积极的是,以下是一些你使用标准\matrix或以下方式matrix of nodes

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart, matrix,fit,backgrounds}
\tikzset{
  box/.style={
    shape=rectangle split, rectangle split parts=4
  },
}
\NewDocumentCommand {\parts} { d () mmmm } {
  \IfValueTF { #1}
  {
    \node (#1) [box] {\nodepart{one} #2 \nodepart{two} #3 \nodepart{three} #4 \nodepart{four} #5};
  }{
    \node[box] {\nodepart{one} #2 \nodepart{two} #3 \nodepart{three} #4 \nodepart{four} #5};
  }
}
\begin{document}
\begin{tikzpicture}
  \matrix (m)[matrix of nodes,column sep=-\pgflinewidth, row sep=-\pgflinewidth,
  draw,align=center] 
  {
    AAA &  EEEEEE \\
  };
  \draw (m-1-1.north west) -- (m-1-2.north east) -- (m-1-2.south east) -- (m-1-1.north west) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}
  \matrix (m)[matrix of nodes,column sep=-\pgflinewidth, row sep=-\pgflinewidth,
  draw,align=center] 
  {
    \node{AAA};  &  \node{EEEEEE}; \\
  };
\end{tikzpicture}
\begin{tikzpicture}
  \matrix (m)[column sep=-\pgflinewidth, row sep=-\pgflinewidth,
  draw,align=center] 
  {
    \parts{AAA}{BBB}{CCC}{DDD}  &  \node{EEEEEE}; \\
  };
\end{tikzpicture}
\begin{tikzpicture}
  \matrix (m)[column sep=-\pgflinewidth, row sep=-\pgflinewidth,
  draw,align=center] 
  {
    \parts(first){AAA}{BBB}{CCC}{DDD}  &  \node (second){EEEEEE}; \\
  };
  \draw (first.north west) -- (second.north east) -- (second.south east) -- (first.north west) -- cycle;
\end{tikzpicture}
\end{document}

[由于 Okular 错误,我现在无法生成可用的图像。]

相关内容