4

I am trying to draw a complex item (consisting of multiple \nodes) as a cohesive whole using a nested \tikzpicture. My outermost picture uses a chain, onto which every \node is put.

My inner picture uses a chain as well, but that's supposed to be a different one than the outer chain.

This structure causes an error:

Package pgf Error: No shape named chain-2 is known.

How can I fix that?

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{chains,scopes,shapes.misc}

\begin{document}
\begin{tikzpicture}[start chain,node distance=5mm,
    every node/.style={on chain},
    connect/.append style={join=by ->},
    point/.style={coordinate},
    l/.style={draw, rounded rectangle, rounded rectangle right arc=0},
    c/.style={draw},
    r/.style={draw, rounded rectangle, rounded rectangle left arc=0},
    cozy/.style={node distance=0}]
\node [point] {};
\node [connect] (lcr) {\tikz{[start chain, cozy]
    \node [l] (l) {L};
    \node [c] (c) {C};
    \node [r] (r) {R};
}};
\node [point, connect] {};
\end{tikzpicture}
\end{document}

Edit: I have utilized @Gonzalo Medina's answer (which uses boxes to store the inner tikzpicture) to get rid of the error. Even though it gets me closer to a solution, my actual situation won't be fixed by it, because now latex seems to think \nodes are at a different location than where the're eventually drawn:

bad positions

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{chains,scopes,shapes.misc}

\newsavebox\mybox
\tikzset{
    l/.style={draw, rounded rectangle, rounded rectangle right arc=0},
    c/.style={draw},
    r/.style={draw, rounded rectangle, rounded rectangle left arc=0},
    cozy/.style={node distance=0pt}
}

\begin{document}
\savebox\mybox{%
\tikz[start chain,every node/.style={on chain},node distance=-\pgflinewidth]
{
    \node [l] (l) {L};
    \node [c] (c) {C};
    \node [r] (r) {R};
}}

\begin{tikzpicture}[start chain,node distance=5mm,
    every node/.style={on chain},
    connect/.append style={join=by ->},
    point/.style={coordinate},
    group/.style={inner sep=0, outer sep=0}]
\node [point] {};
\node [connect, group] (lcr) {\usebox\mybox};
\node [point, connect] {};
{[]
    \draw[->] (0,-1) -- (l.south east);
}
\end{tikzpicture}
\end{document}

Maybe I just need to get rid of the chain in my nested picture... or for that matter, the lose the entire nested picture, and stick to a single level of tikz.

derabbink
  • 1,640
  • 2
    I think nesting tikzpictures is not a good idea. What is it that you are trying to achieve? See for instance Problem with overlay when a tikzpicture is inside another tikzpicture. – Peter Grill Feb 20 '14 at 17:52
  • I want to draw a chain where one of the nodes on the chain is a complex shape of my own design. This shape happens to be constructed using a chain as well. Later on, I want to draw arrows pointing towards components of the inner tikzpicture, across the entire image. – derabbink Feb 20 '14 at 17:57
  • Sounds like you need \tikzmark, but not sure without seeing a picture of what is desired. See the link in the first comment as to why it isn't a good idea. – Peter Grill Feb 20 '14 at 17:58
  • 2
    Just a thought: any possibility of using the new "pic" functionality for this? – Paul Gessler Mar 28 '14 at 19:14
  • Start by giving the chains proper names, i.e. start chain=outer chain and start chain=inner chain (→ on chain=outer chain, on chain=inner chain), otherwise TikZ might not differentiate between them. If you're just going right (the default direction of a chain) you could just use a \matrix (e.g. the \tikzCenterNodes macro can help here). A matrix is almost a node in itself. Maybe you actually need a branch or something totally different. – Qrrbrbirlbel Nov 25 '22 at 14:41
  • Without much information about the end product I'd vote to close this question. – Qrrbrbirlbel Nov 25 '22 at 14:41

0 Answers0