Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to use a TikZ matrix along a chain?

The following code attempts to create a chain consisting of a node, a matrix, and another node.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,chains}

\begin{document}

\begin{tikzpicture}[start chain]
  \node [on chain] {XYZ};

  \matrix [on chain]
  {
    \node {A}; \\
    \node {B}; \\
    \node {C}; \\
  };

  \node [on chain] {123};
\end{tikzpicture}

\end{document}

However, if I try to compile, I get the error "Package pgf Error: No shape named chain-2 is known." (Interestingly, if I remove the final node so that nothing follows the matrix, then it compiles without error.) Why does this error occur?

Of course, it is straightforward enough to use the positioning library directly. So, mostly, I am interested in this question for its own sake; I don't have an important, specific use in mind where chains of matrices would be critical.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

The nodes on the chains are named as (chainname-#) but this naming scheme is not provided to the matrix (seems like a bug). So the safest way is to name your matrix nodes on the chain explicitly.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,chains,matrix}
\begin{document}
\begin{tikzpicture}[start chain]
  \node [on chain] {XYZ};
  \node [on chain] {123};
  \node [on chain,matrix of nodes]  (chain-3) {    A \\    B \\    C \\  };
  \node [on chain] {$\alpha\beta\gamma$};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Your suggestion of explicitly naming the matrix with (chain-3) does indeed work. However, when I try naming the chain in your code with start chain=mychain and on chain=mychain, I get the same error as before unless I continue to explicitly name the matrix with (mychain-3). Is something more going on here? –  Henry DeYoung Jun 16 '12 at 15:24
    
Thinking back to this question, I am not sure that I understand why there is a naming clash between chains and matrices. If I try \matrix (mat) [matrix of nodes] { A \\ B \\ C \\ D \\ }; \draw[fill,blue] (mat-1) circle (2pt);, I get the error that "No shape named mat-1 is known." Why does this then conflict with the way a chain is named, if mat-1 doesn't appear to be used in ordinary matrix construction? –  Henry DeYoung Jun 20 '12 at 21:14
    
@HenryDeYoung You need to use (mat-1-1) even though it's a vector. The problem is that the matrix is full of nodes but none of them gets the proper chain name. So it needs to be explicitly stated. But you are right I should have mentioned it in the answer. –  percusse Jun 20 '12 at 22:19
    
My above comment wasn't very clear. I was trying to use the circle at mat-1 to show that a matrix named mat doesn't actually define any point named mat-1, which is indeed confirmed by the error message that I got. Given this, then, I don't understand why there is a naming clash between chain names and matrix names. Why doesn't TikZ just assign the proper chain name (e.g., chain-3) to the matrix itself (as opposed to hoping that one of the nodes within the matrix will have the proper name for inclusion on the chain)? –  Henry DeYoung Jun 22 '12 at 17:15
    
@HenryDeYoung I don't know exactly the problem but the problem with such syntax is that TikZ always decides what to do by scanning the next character. And most probably - character directly steers the algorithm to matrix part of the code. But there is no matrix node with the name chain such that TikZ can keep on parsing the particular subentry e.g. (chain-3-5) etc. So it knows that it's a matrix but cannot parse it since (chain-3) is missing the column part. That's probably why it gets confused. –  percusse Jun 22 '12 at 23:01

I ran into the same issue, and I worked around it by putting the matrix inside a nested tikzpicture i.e.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,chains}

\begin{document}

\begin{tikzpicture}[start chain]
  \node [on chain] {XYZ};

  \node [on chain] {
    \begin{tikzpicture}
      \matrix
      {
        \node {A}; \\
        \node {B}; \\
        \node {C}; \\
      };
    \end{tikzpicture}
  };
  \node [on chain] {123};
\end{tikzpicture}

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.