2

I try to use multipart nodes in matrix and draw lines with cell name. Below code report error:(use pure text works fine)

 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...

code:

\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}
3
  • 1
    You're overriding the standard construction of the node in the cell, so the name (m-1-1) and the name (m-1-2) are not applied i.e. even in the case where there is no multipart shape involved. Don't use \node ... ; if you want to use the (<name>-<row>-<col>) of the matrix library.
    – cfr
    Commented Apr 2 at 15:17
  • what's not proper way to draw such graphs? tabular?
    – beetlej
    Commented Apr 2 at 15:18
  • It depends what you want to do. I've put some possibilities in an answer below using the matrix stuff, but a tabular would also be a possibility (perhaps with tikzmark). Personally, I'm not keen on the multipart nodes in TikZ, but maybe that's just me. They never seem to work as I want them to ;).
    – cfr
    Commented Apr 2 at 15:37

1 Answer 1

4

In a matrix of nodes, \node (<name>-<row>-<col>) {<content>}; is inserted for you. If you start the content of a cell with a backslash, this is overridden, but then the naming is obviously up to you.

More positively, here are some things you can do with either a standard \matrix or a 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}

[I can't produce usable images right now due to an Okular bug.]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .